title: JWT nodejs / express - Invalid signature
body: <p>I'm having trouble with Jwt and especially an error "Invalid Signature".</p>
  
  <p>I'm generating a token after the user logs in (jsonwebtoken).</p>
  
  <pre><code>userSchema.methods.generateJwt = function() {
    var expiry = new Date();
    //expiry.setDate(expiry.getDate() + 7);
  
    expiry.setDate(expiry.getDate() + 2);
    return jwt.sign({
      _id: this._id,
      username: this.username,
      name: this.lastname,
      exp: parseInt(expiry.getTime() / 1000),
    }, process.env.SRCT,  {
      algorithm: 'HS256'
    });
  }
  </code></pre>
  
  <p>Then I'm creating an express-jwt middleware to add it to routes :</p>
  
  <pre><code>var auth = jwt({
    secret: process.env.SRCT,
    userProperty: 'payload'
  });
  </code></pre>
  
  <p>Used like this :</p>
  
  <pre><code>router.get('/', auth, ctrlUser.slash);
  </code></pre>
  
  <p>My JWT created is passed in the front end request (Authorization bearer) and is the same as the one created right after the login, according to the debugger.</p>
  
  <p>But unfortunatly, I'm still having the error {"message":"UnauthorizedError: invalid signature"} after each request to the nodejs backend.</p>
  
  <p>Could someone tell me what I am doing wrong to have an invalid signature?</p>
  
  <p>Thanks in advance</p>