tokenNotExpired() always return false
See original GitHub issueHi, I use your library without Ionic (native Angular 2) and all time tokenNotExpired() method return false.
When this code is exectued :
loggedIn() {
console.log(tokenNotExpired());
return tokenNotExpired();
}
constructor(private router: Router) {}
canActivate() {
console.log(this.loggedIn());
if(this.loggedIn()) {
return true;
} else {
this.router.navigate(['login']);
return false;
}
}
I use this code for angular routing canActivate: [AuthGuard].
But tokenNotExpired() always return false.
I don’t understand why !
Issue Analytics
- State:
- Created 6 years ago
- Comments:31 (2 by maintainers)
Top Results From Across the Web
angular2-jwt token alwas not valid - Stack Overflow
I have a service that verifies everytime a route is called if the jwt token is valid or not using the angular2-jwt tokenNotExpired()...
Read more >Issues with the Angular2 Quickstart - Auth0 Community
Another of the issues is that the use of angular2-jwt is incorrect and does not work. There's an issue where tokenNotExpired always returns...
Read more >How do you handle token refreshing? - Ionic Forum
So in the token provider I can just use something like angular2-jwt's tokenNotExpired() function that returns true or false depending on if ...
Read more >Refreshing Tokens — flask-jwt-extended 4.4.4 documentation
The basic idea here is that at the end of every request, we will check if there is a JWT that is close...
Read more >Authentication And Authorization In Angular - Part Twelve
Don't be scared by watching the above code, always write the simple code. ... So here we can simply return tokenNotExpired().
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I found the solution, as I was fighting with a similar error: The error is induced by Commit a6984d1df9315cc52b22b9c57b8badc4b6d1f47 (update token name). With this commit, angular2-jwt assumes that the standard name of the token is token , not any longer access-token. The problem can be traced to the Quickstart of Auth0 for Angular 2 (https://auth0.com/docs/quickstart/spa/angular2/01-login), as it states (as of time of writing this):
So there are two possible fixes: -Change in the constructor from
localStorage.setItem('id_token', authResult.idToken)
tolocalStorage.setItem('token', authResult.idToken)
-Use
tokenNotExpired('id_token')
instead oftokenNotExpired()
The third, impossible and stupid solution would be changing the default token name in JWT again.
so return !isTokenExpired()