-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
posts/angular/refreshing-authorization-tokens-angular-6/ #17
Comments
Great article. Followed these steps and successfully implemented refreshing tokens in Angular 8. Thank You. |
Nice article. Can you please explain the purpose of the second if condition in the below code |
Nice article. Can you please explain the purpose of the second if condition in the below code. Will the code enter the second if. Because authService.refreshToken() will always return an observable and it wont be null or undefined. if (!this.inflightAuthRequest) {
this.inflightAuthRequest = authService.refreshToken();
if (!this.inflightAuthRequest) {
// remove existing tokens
localStorage.clear();
this.router.navigate(['/sign-page']);
return throwError(error);
}
} |
Thanks. The first checks if there is an inflight request from a previous HTTP Request attempting to request and shares the request. The second once checks if an attempt to set the inflight request is successful. It might fail if the refresh token is absent and hence redirects the user to the sign-in page. |
I think, even if the refresh token is absent, a http call will be made and it is going to be an async operation. So at the second if condition, we would be having the request handlers in this.inflightAuthRequest. So i guess !this.inflightAuthRequest will always be false |
Hi Maina! I am having an issue when following the tutorial and created a StackOverflow post about it. Can you please tell me what I am doing wrong. The post is: https://stackoverflow.com/questions/59884040/issue-with-creating-refresh-token-via-httpinterceptor |
@dfmmalaw I answered your question. Thanks. |
Refreshing Authorization Tokens – Angular 6
In this post, we are going to build a http interceptor for refreshing authorization tokens once expired in Angular 6 and RXJS6.
https://codinglatte.com/posts/angular/refreshing-authorization-tokens-angular-6/
The text was updated successfully, but these errors were encountered: