Skip to content
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

Open
utterances-bot opened this issue Sep 11, 2019 · 7 comments
Open

posts/angular/refreshing-authorization-tokens-angular-6/ #17

utterances-bot opened this issue Sep 11, 2019 · 7 comments

Comments

@utterances-bot
Copy link

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/

Copy link

Great article. Followed these steps and successfully implemented refreshing tokens in Angular 8. Thank You.

Copy link

bobinjv commented Nov 13, 2019

Nice article. Can you please explain the purpose of the second if condition in the below code

Copy link

bobinjv commented Nov 13, 2019

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);
  }
}

@mainawycliffe
Copy link
Member

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.

Copy link

bobinjv commented Nov 14, 2019

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

Copy link

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

Copy link
Member

@dfmmalaw I answered your question. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants