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

201
Views
Cómo comprobar si un token de twilio ha caducado

Tengo un proyecto nextjs y necesito verificar si un token twilio está vencido o no.

Pensé en usar la biblioteca jwt-decode para decodificar el token y tomar el atributo exp de él, luego compararlo con la fecha real. El problema es que la fecha de caducidad parece estar rota porque siempre es en 1970.

Por ejemplo, acabo de crear este token:

 { "jti": "SKbec4a565d0598f1e4130f65db51a8345-xxxxxxxxxx", "grants": { "identity": "618f7ef057c2923be10dfd1d", "chat": { "service_sid": "ISbffc1a6c2f8647ac8a6774xxxxxxxxxx" } }, "iat": 1649879042, "exp": 1649882642, "iss": "SKbec4a565d0598f1e4130f6xxxxxxxxxx", "sub": "AC1d09a2edee3f481fbd1dafxxxxxxxxxx" }

Si hago new Date(1649882642) resulta ser 1970-01-20T02:18:02.642Z . Siempre.

¿Tal vez debería especificar el vencimiento del token cuando lo creo? Lo creé siguiendo el documento oficial . Entonces, ¿qué debo hacer para determinar si un token es válido o no?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Los valores iat y exp en un Twilio JWT son el tiempo en segundos desde la época (1 de enero de 1970).

Sin embargo, las fechas en JavaScript se miden en milisegundos desde la época .

Entonces, para ajustar el tiempo en segundos a la fecha en JavaScript, primero debe multiplicar por 1,000.

 const exp = decodedToken.exp; const expiryDate = new Date(exp * 1000);

En tu ejemplo, eso se ve así:

 const exp = 1649882642; const expiryDate = new Date(exp * 1000); expiryDate.toISOString(); // => 2022-04-13T20:44:02.000Z
about 4 years ago · Santiago Gelvez 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!