I dont want my token to get expire and shold be valid forever.
var token = jwt.sign({email_id:'[email protected]'}, "Stack", { expiresIn: '24h' // expires in 24 hours });
In above code i have given for 24 hours.. I do not want my token to get expire. What shall be done for this?
The most common solution is to reduce the duration of the JWT and revoke the refresh token so that the user can't generate a new JWT. With this setup, the JWT's expiration duration is set to something short (5-10 minutes) and the refresh token is set to something long (2 weeks or 2 months).
At maximum, the expiration period can be set up to 24 hours from time of issue. Note: This is an expiration time for the JWT token and not the access token. Access token expiration is set to 24 hours by default. “
verify method to a function that returns a promise and assign it to jwtVerifyAsync . Then we call jwtVerifyAsync with the token and the token secret to check if the token is valid. If it's expired, then it's considered invalid and an error will be thrown.
The exp
claim of a JWT is optional. If a token does not have it it is considered that it does not expire
According to documentation of https://www.npmjs.com/package/jsonwebtoken the expiresIn
field does not have a default value either, so just omit it.
There are no default values for expiresIn, notBefore, audience, subject, issuer. These claims can also be provided in the payload directly with exp, nbf, aud, sub and iss respectively, but you can't include in both places.
var token = jwt.sign({email_id:'[email protected]'}, "Stack", {});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With