0

The problem is that when comparing both dates the token would expire in approximately 17 hours, which is wrong, since at the time of generation it should be only 1 minute longer.

If someone can help me I appreciate it very much

Miguel
  • 119
  • 3
  • 11

1 Answers1

1

It looks like your code assumes that the expiration and issued at properties are defined as milliseconds (60000 milliseconds = 60 seconds = 1 minute).

However, the JWT specification states that exp and iat use 'Seconds since the Epoch. See the answer here: https://stackoverflow.com/a/39926886/12086953

So just change the value in your first code snippet to expire in 60 seconds rather than 60000 seconds (which is just under 17 hours), like this:

const myToken = jwt.sign({ id: '12345677', username: 'emailtest@uu.com' }, 'mysecretjsonwebtoken', { expiresIn: 60, audience: '12345677' })
Chris Brenberg
  • 142
  • 1
  • 6