ramitaherwahdan1978 says:
token = localStorage.getItem(
"token"
);
The localStorage.getItem returns null. So use the nullish coalescing operator (??) to return the number 0 if localStorage returns null.
token = localStorage.getItem("token") ?? 0;
Reference: https://jasonwatmore.com/post/2022/11/10/angular-fix-for-argument-of-type-string-null-is-not-assignable-to-parameter-of-type-string
token = localStorage.getItem("token");
timeLeft = 120;
minutes = this.timeLeft / 60 % 60;
seconds = this.timeLeft % 60;
interval = setInterval(() =>
{
if (this.token > 0)
{
const parseJwt = (this.token);
const decode = JSON.parse(atob(this.token.split('.')[1]));
if (decode.exp * 1000 >= new Date().getTime())
{
if(this.seconds == 0)
{
this.minutes--;
this.seconds = 59;
}
else if(this.seconds <= 59)
{
this.seconds--;
}
else if((this.minutes == 0) && (this.seconds == 0))
{
clearInterval(interval);
}
}
}
},1000)