title: 403 forbidden expressjs backend
body: <pre><code>GET http://localhost:5000/booksIdea/show 403 (Forbidden)
  </code></pre>
  
  <p>i check the token in the website <a href="https://jwt.io/" rel="nofollow noreferrer">https://jwt.io/</a> i got invalid signature so i guess why the problem came from but i ignore how to fix it
  i searched abt this error and this is what i found : Receiving a 403 response is the server telling you, “I’m sorry. I know who you are–I believe who you say you are–but you just don’t have permission to access this resource. Maybe if you ask the system administrator nicely, you’ll get permission. But please don’t bother me again until your predicament changes.”</p>
  
  <p></p>
  
  <p>API GET function on front end:</p>
  
  <pre><code>import axios from 'axios'
  
  export const ShowBooks = () =&gt; {
      let token = localStorage.getItem("usertoken")
  
      return axios.get("http://localhost:5000/booksIdea/show", {
          headers: {
            Authorization: `Bearer ${token}`, //here remove + in template litereal
          },
        })
        .then(res =&gt; {
            console.log("Success")
        })
        .catch(error =&gt; {
          console.log(error)
        })
  
  }
  </code></pre>
  
  <p>backend app.js</p>
  
  <pre><code>const express = require('express')
  var cookieParser = require('cookie-parser')
  const app = express()
  var cors = require('cors')
  var bodyParser = require('body-parser')
  const port = 5000
  const routes = require("./routes");
  const con = require('./db')
  var cors = require('cors')
  app.use(cors())
  // database connect 
  
  con.connect(function(err) {
      if (err) throw err;
      console.log("Connected!");
    });
  
    //cookie 
    app.use(cookieParser())
  //routes
  // support parsing of application/json type post data
  app.use(bodyParser.json());
  
  //support parsing of application/x-www-form-urlencoded post data
  app.use(bodyParser.urlencoded({ extended: true }));
  
  app.use("/", routes);
  
  
  app.listen(port, () =&gt; console.log(`Example app listening on port ${port}!`))
  </code></pre>
  
  <p>here is routes </p>
  
  <pre><code>var express = require('express')
  var router = express.Router()
  var Controller = require('./controller')
  var authController = require('./authController')
  var BooksIdeaController = require('./BooksIdeaController')
  router.post('/register',Controller.register);
  router.post('/login',authController.login);
  router.post('/booksIdea/:id',authController.verify,BooksIdeaController.addComment)
  router.post('/booksIdea/addbook',authController.verify,BooksIdeaController.addBookIdea)
  router.get('/booksIdea/show',authController.verify,BooksIdeaController.showBookIdea)
  router.put('/booksIdea/edit/:id',authController.verify,BooksIdeaController.UpdateBookIdea)
  router.delete('/booksIdea/delete/:id',authController.verify,BooksIdeaController.DeleteBookIdea)
  module.exports = router;
  </code></pre>
  
  <blockquote>
    <p>authController</p>
  </blockquote>
  
  <pre><code>const con = require('./db');
  var bcrypt = require('bcrypt');
  let jwt = require('jsonwebtoken');
  const express = require('express')
  var cookieParser = require('cookie-parser')
  const app = express()
  module.exports.login=function(req,res){
      var username=req.body.name;
      var password=req.body.password;
      con.query('SELECT * FROM users WHERE username = ?',[username], function (error, results, fields) {
        if (error) {
            res.json({
              status:false,
              message:'there are some error with query'
              })
        }else{
          if(results.length &gt;0){
            bcrypt.compare(password, results[0].password, function (err, result) {
              if (result == true) {
          jwt.sign({user:results},'configSecret',(err,token)=&gt;{
            res.json({
              token:token
            })
  
  
          });
  
  
  
              //   res.json({
              //     status:true,
              //     message:'successfully authenticated'
              // })
              } else {
                res.json({
                        status:false,
                        message:"username and password does not match"
                       });
              }
            });
          }
          else{
            res.json({
                status:false,    
              message:"username does not exits"
            });
          }
        }
      });
  }
  
  module.exports.home=function(req,res){
  res.send('hello');
  }
  //////
  // if(password==results[0].password){
  
    // }else{
    //    
    // }
    module.exports.verify = function verifyToken(req, res, next) {
      // Get auth header value
      const bearerHeader = req.headers['authorization'];
      // Check if bearer is undefined
      if(typeof bearerHeader !== 'undefined') {
        // Split at the space
        const bearer = bearerHeader.split(' ');
        // Get token from array
        const bearerToken = bearer[1];
        // Set the token
        req.token = bearerToken;
        // Next middleware
        next();
      } else {
        // Forbidden
        res.sendStatus(403);
      }
  
    }
  </code></pre>
  
  <p>How can I fix this error? thank you in advance for your help</p>