Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

358
Views
expiresIn not working in jsonwebtoken.sign() even with object literal

Here is my code, as you can see, I am using an object literal as suggested in the jsonwebtoken library help, but the result is always the same

  const TOKEN = {
    JWT: JWT.sign({
      iat: Date.now(),
      data: {
        username: USER.name,
        userLevel: USER.level,
        userId: USER._id,
        limit: USER.limit,
        has2FA: USER.has2FA
      }
    }, SECRET_KEY,
    { expiresIn: 60 * 60 * 12 }
    )
  }

As you can see, this code returns both the iat and exp with just a few minutes and seconds of difference instead of the 12 hours that I want.

Any ideas on why is this happening?

enter image description here


Edit: I am using jsonwebtoken and Dayjs to display the time.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The problem seems to be related to the fact that you are specifying iat in milliseconds whereas it's expected to be in seconds. So either do

iat: Date.now()/1000,

or completely remove that property because that's the default value anyway.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!