Issue
I am trying to check the expiry of JWT token for an angular app using the following:
private tokenExpired(token: string) {
const expiry = (JSON.parse(atob(decodeURIComponent(token.split('.')[1])))).exp;
return (Math.floor((new Date).getTime() / 1000)) >= expiry;
}
I am getting error
main-es2015.a58e5846e0db8a93ea88.js:1 ERROR Error: Uncaught (in promise):
InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not
correctly encoded.
Error: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly
encoded.
at A.tokenExpired (main-es2015.a58e5846e0db8a93ea88.js:1)
at A.canActivate (main-es2015.a58e5846e0db8a93ea88.js:1)
at main-es2015.a58e5846e0db8a93ea88.js:1
at A._subscribe (main-es2015.a58e5846e0db8a93ea88.js:1)
at A._trySubscribe (main-es2015.a58e5846e0db8a93ea88.js:1)
at A.subscribe (main-es2015.a58e5846e0db8a93ea88.js:1)
at PB.call (main-es2015.a58e5846e0db8a93ea88.js:1)
at A.subscribe (main-es2015.a58e5846e0db8a93ea88.js:1)
at k (main-es2015.a58e5846e0db8a93ea88.js:1)
at L._innerSub (main-es2015.a58e5846e0db8a93ea88.js:1)
at T (polyfills-es2015.6022d6f28e0500e60d30.js:1)
at T (polyfills-es2015.6022d6f28e0500e60d30.js:1)
at polyfills-es2015.6022d6f28e0500e60d30.js:1
at l.invokeTask (polyfills-es2015.6022d6f28e0500e60d30.js:1)
at Object.onInvokeTask (main-es2015.a58e5846e0db8a93ea88.js:1)
at l.invokeTask (polyfills-es2015.6022d6f28e0500e60d30.js:1)
at i.runTask (polyfills-es2015.6022d6f28e0500e60d30.js:1)
at m (polyfills-es2015.6022d6f28e0500e60d30.js:1)
The problem is happening on only one client machine. I tried replacing spaces and new lines and using 'window.atob' instead of 'atob' but nothing has helped so far.
private tokenExpired(token: string) {
var base64Url = token.split('.')[1];
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/').replace(/\s/g, '');
const expiry = (JSON.parse(decodeURIComponent(window.atob(base64)))).exp;
return (Math.floor((new Date).getTime() / 1000)) >= expiry;
}
I looked at lots of similar posts but didn't find a solution that could help me. Can someone throw a light on why this is happening on some machine only (all three browsers - Chrome, Edge, Firefox) and not on other machines?
Solution
Clearing the cache, cookies, cache etc solved the problem.
Answered By - Ram
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.