Hello, there is such code:

async.waterfall([ function(done){ User.findById(verifiedJwt.body.sub, function(err, user) { if (err) return next(err); if (!user) return res.status(401).json({ error: 'Incorrect token credentials' }); req.user = user; done(null); }); } ], function(err){ if (err) return next(err); verifiedJwt.setExpiration(new Date().getTime() + (60*60*1000)); return next(); }); 

This code is called when a user navigates along one of the routes, and is responsible for extending the token's lifetime. The very extension of the life of the token occurs here

 verifiedJwt.setExpiration(new Date().getTime() + (60*60*1000)); 

And if you believe the documentation module , then everything should work. But in practice this does not happen.

UPDATE Remade everything under the jsonwebtoken module.

  jwt.verify(token, secrets.sessionSecret, function (err, verifiedJwt) { if (err){ if (err.message === 'jwt expired'){ req.user = null; console.log(err); return res.redirect('/login'); } return res.redirect('/login'); } async.waterfall([ function(done){ User.findById(verifiedJwt.data, function(err, user) { if (err) return next(err); if (!user) return res.status(401).json({ error: 'Incorrect token credentials' }); req.user = user; done(null); }); } ], function(err){ if (err) return next(err); console.log("before", verifiedJwt); verifiedJwt.exp = Math.floor(Date.now() / 1000) + (60*60); console.log("after",verifiedJwt); return next(); }); }); 

Token life time is changed like this:

  function(err){ if (err) return next(err); console.log("before", verifiedJwt); verifiedJwt.exp = Math.floor(Date.now() / 1000) + (60*60); console.log("after",verifiedJwt); return next(); }); 

But in fact it is not updated ..

  • It reaches that place, does not fall stupidly into error handling? By the way, I wouldn’t pull the library version 0.3.2 with a hundred stars in your place, but I would pull this from almost 4k stars: github.com/auth0/node-jsonwebtoken - Duck Learns to Hide
  • @ DUCK LEARNING RESUMED under the recommended module. But I did not find a method for extending the life of the token there, so I changed it in my own way. Updated the question, please see what is wrong) - Maxim Cherevatov
  • I don’t know, I’m generally according to the note as far as I just walked past) I don’t see with my gaze, I’ve got to have a good time - Duck Learns to Hide

0