title: Node.js - Express.js JWT always returns an invalid token error in browser response
body: <p>I'm using node.js and express.js with the <a href="https://www.npmjs.org/package/express-jwt" rel="noreferrer">express-jwt</a> module, and I have set up a simple HTTP server to test everything:</p>
  
  <p>This is the node code involved:</p>
  
  <pre><code> app.set('port', process.env.PORT || 3000);
      app.use(express.methodOverride());
      app.use(allow_cross_domain);
      app.use('/api', expressJwt({secret: '09qrjjwef923jnrge$5ndjwk'}));
      app.use(express.json());
      app.use(express.urlencoded());
      app.use('/', express.static(__dirname + '/'));
      app.use(function(err, req, res, next){
        if (err.constructor.name === 'UnauthorizedError') {
          res.send(401, 'Unauthorized');
        }
      });
  
      app.get('login',function(req,res){
  
      //...
      jwt.sign(results.username+results.email, secret, { expiresInMinutes: 9000000000*9393939393393939393939 });
      });
  
      app.post('api/profile',function(req,res){
       console.log(req.user); // this return undefined in console
       res.send(req.user); // response is pending and dunno why it returns error in browser console
      });
  </code></pre>
  
  <p>So once I open the <code>/login</code> URL I get logged in and I send the session token to <code>api/post</code>, which returns this response error in the browser console:</p>
  
  <pre><code>{"error":{"message":"invalid signature","code":"invalid_token","status":401,"inner":{}}}
  </code></pre>
  
  <p>I don't understand why this is happening, because the token stored in the front-end and the token in JWT are the same. What could be the reason for this error?</p>
  
  <p>An example of headers <code>POST</code>ed to the <code>api/post</code> URL: </p>
  
  <p><img src="https://i.stack.imgur.com/bfnc8.png" alt="enter image description here"></p>