set token to expiration with passport jwt.
const jwt = require('jsonwebtoken'); // in your login route router.post('/login', (req, res) => { // do whatever you do to handle authentication, then issue the token: const token = jwt.sign(req.user, 's00perS3kritCode', { expiresIn: '30m' }); res.send({ token }); });
Here is what the above code is Doing:
1. We’re importing the jsonwebtoken library.
2. We’re creating a login route that will issue a token.
3. We’re using the jsonwebtoken library to create a token using the user object, a secret string, and an expiration time.
4. We’re sending the token back to the client.
Now, we need to protect our routes.