Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set jwt token expiry time to maximum in nodejs?

Tags:

node.js

jwt

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?

like image 691
Jagadeesh Avatar asked Jul 20 '17 06:07

Jagadeesh


People also ask

How can I increase my JWT token expiry time?

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).

What is the max expiration time accepted by JWT tokens?

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. “

How do I know if my JWT token is expired node JS?

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.


1 Answers

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", {}); 
like image 112
pedrofb Avatar answered Sep 28 '22 01:09

pedrofb