Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

359
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda