Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

364
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda