I have module to check if the expiration date of token is already expired or not. so if ever the token is expired it will automatically the page will go to login again.
I already code it but their is error in my console and my page is loading anymore.
Uncaught InvalidTokenError {message: "Invalid token specified"}

List not working
This is my code:
if (localStorage.getItem("token") === null) {
let token_expired = localStorage.getItem('token');
let decoded = decode(token_expired, { header: true });
let decode_string = decoded["exp"];
var current_time = Date.now() / 1000;
if(decode_string < current_time)
{
localStorage.clear();
}
}
I think that your token does not exist.
Go inside dev tools (ctrl +shift + i) then
Select Application
Inside the Application go to Storage then
Open Local Storage (double click on local storage) then
Clear local storage
I think you need to change the first condition, and use declarative names for variables.
const storedToken = localStorage.getItem("token");
if (storedToken){
let decodedData = decode(storedToken, { header: true });
let expirationDate = decodedData.exp;
var current_time = Date.now() / 1000;
if(expirationDate < current_time)
{
localStorage.removeItem("token");
}
}
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