DEV Community


"expiresIn" should be a number of seconds or string representing a timespan - JWT

thiagoanjos profile image Thiago ・1 min read

I had set TOKEN_EXPIRATIONS=7d on my .env file and was not working properly. So I found 2 ways to fix the problem:

1) On .env file write: JWT_EXPIRE=somethingYouWant
2) On .env file write: TOKEN_EXPIRATION = 7d ( example ) and in your sign method JWT you can do this:
const token = JWT.sign({ id, email }, process.env.TOKEN_SECRET, {
expiresIn: parseInt(process.env.TOKEN_EXPIRATION),

Discussion (0)

Editor guide