Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  144] [ 2]  / answers: 1 / hits: 21364  / 6 Years ago, tue, october 23, 2018, 12:00:00

Good day,



I'm using jwt in my authentication. I already decoded my token but the problem is, I want to check if the token exp is already expired or not.



var decodedToken = localStorage.getItem('user_token');

console.log(decodedToken.exp) // writes 1540360205


Thank you in advance.


More From » date

 Answers
59

It appears that the exp claim of your JWT tokens is bearing a UNIX timestamp, in seconds. To check if a given JWT is expired then you can just compare against the current date as a UNIX timestamp:


var decodedToken = localStorage.getItem('user_token');
if (decodedToken.exp < new Date()/1000) {
console.log("EXPIRED");
}

[#53274] Thursday, October 18, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jackie

Total Points: 442
Total Questions: 107
Total Answers: 94

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
jackie questions
Sat, Sep 18, 21, 00:00, 3 Years ago
Wed, Jul 14, 21, 00:00, 3 Years ago
;