node.jsjwt

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


I dont want my token to get expire and should be valid forever.

var token = jwt.sign({ email_id: "123@gmail.com" }, "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?


Solution

  • 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 the 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 them in both places.

    var token = jwt.sign({email_id:'123@gmail.com'}, "Stack", {});