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.
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");
}
This should get you the local time then you can compare it with current date and time and check if the token has expired
var tokenDate = new Date(parseInt(localstorage.getItem('user_token')) * 1000)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With