DEV Community

Thiago
Thiago

Posted on

1

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

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),
});

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs