so I want to require the token because acces to the application. And when I try to catch the token it send me error403 forbidden so “no token”. I miss something but I don’t know what if somebody have an idea let me know ! thanks 🙂

this is my React/app.js

import "./App.css";
import React from "react";
import Route from './components/Route';
import axios from "axios";

function App() {

  axios({
    method: "get",
    url: `${process.env.REACT_APP_API_URL}jwtid`, 
    withCredentials: true, 
  }).then((res) => {
    console.log(res);
    console.log(res.data)
  })
  .catch((err) => console.log("No token"))

  return (
    <div> 
      <Route/>
    </div> 
  );
}

export default App;

This is my Backend App.js

const express = require("express");
//crééer un application express
const path = require("path");
const Sequelize = require("sequelize");
const cookieParser = require('cookie-parser')
const app = express();

const {verifyToken, authJwt} = require('./middleware/authJwt');
//variable d'environnement

require("dotenv").config();
console.log(process.env);

//import des routes
const authRoutes = require("./routes/user");
const commentRoutes = require("./routes/comment");

//intercepter toute requête d'un contenttype.json
app.use(express.json());

const cors = require('cors');
const corsOptions ={
    origin:'http://localhost:3000/', 
    credentials:true,            //access-control-allow-credentials:true
    optionSuccessStatus:200
}
app.use(cors({credentials: true,
             origin: 'http://localhost:3000', 
             allowedHeaders: ["sessionId", "Content-Type"],
             exposedHeaders: ["sessionId"],
             methods: "GET, HEAD, PUT, PATCH, POST, DELETE",
             preflightContinue: false,
            }));

app.use(cookieParser());


//jwt
app.get('/jwtid', verifyToken, (req, res) => {
  res.status(200).send(res.locals.id)
});

//Gestion de la ressource images de façon statique
app.use("/images", express.static(path.join(__dirname, "images")));

//routes
app.use("/api/auth", authRoutes);
app.use("/api/comment", commentRoutes);

// pour exporter l'application/constante pour acceder aux fichiers depuis notre server node

module.exports = app;

And this is my authJwt.js (with the verify token)

const jwt = require("jsonwebtoken");
const config = require("../config/auth.config.js");


verifyToken = (req, res, next) => {
  const token = req.cookies.jwt;
  if (!token) {
    return res.status(403).send({
      message: "No token provided!"
    });
  }
  jwt.verify(token, config.secret, (err, decoded) => {
    if (err) {
      return res.status(401).send({  
        message: "Unauthorized!"
      });
    }
    req.id = decoded.id;
    next();
  });
};

const authJwt = {
  verifyToken: verifyToken,
};

module.exports = authJwt;

And here is my user/controllers with the token call

const bcrypt = require("bcrypt");
const jwt = require("jsonwebtoken");
const config = require("../config/auth.config");
const { User } = require("../models");


module.exports.signup = async (req, res) => {
  if (!req.body.email || !req.body.password) {
    res.status(400).send({
        status: false,
        message: 'une erreur dans create est survenu'
    });
} else {
  let { nom, prenom, email, password, status} = req.body;
  const salt = await bcrypt.genSalt(10);
  password = await bcrypt.hash(password, salt)
    const user = await User.create({
      nom, prenom, email,  password, status
    })
    .then((user) => res.status(201).send(user)).catch((error) => {
      console.log(error);
      res.status(400).send(error);
  });
  }
};


module.exports.login = async (req, res) => {
  const user = await User.findOne({
    where: {
      email: req.body.email
    }
  })
    .then(user => {
      if (!user) {
        return res.status(404).send({ message: "User Not found." });
      }
   
      const passwordIsValid =   bcrypt.compareSync(req.body.password, user.password);
      if (!passwordIsValid) {
        return res.status(401).send({
          accessToken: null,
          message: "Invalid Password!"
        });
      }
      var token = jwt.sign({ id: user.id }, config.secret, {
        expiresIn: 86400 // 24 hours
      });
      const maxAge = 3*24*60*60*1000;
      res.cookie("jwt", token, {httpOnly: true, maxAge});
      res.status(201).send({
        id: user.id,
        nom: user.nom,
        email: user.email,
        password: user.password,
        accessToken: token
      });
    })
    .catch(err => {
      res.status(500).send({ message: err.message });
    });
};


module.exports.profil  = async (req, res) => {
  try {
    let { status, image} = req.body;
    image = `${req.protocol}://${req.get("host")}/images/${req.file.filename}`,
    Comment.create({
      status, image
    }).then((comment) => res.status(201).send(comment))
  } catch (error) {
    console.log(error);
    return res.send(`Error when trying upload images: ${error}`);
  }
};