Giter Site home page Giter Site logo

jwt-auth-angular's Introduction

jwt-auth-angular's People

Contributors

bartosz-io avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jwt-auth-angular's Issues

Not working if "refreshToken" response 401

Hallo!

Thx for your code! But it has an issue. If your token has expired and we call the refreshToken function on backend, and as example it response 401, too (our refresh token was expired, too as example). Then the code don't working. It hangs in "handle401Error" method. I think the reason for this is that the second 401 error (from refreshToken) cannot be handled - it goes to handle401Error, too and nothing else happened.

Use your code, change only the backend for returning new token/refresh token (for this example) to this as example:
return res.status(401).json({message: "some error in refresh token"})

Greetings, Flo

Adding subscribe() makes the call, but doesn't return the data to the original caller.

I can only get the handle401Error to work if I add subscribe() to the end of the pipe in the function observables. That allows my app to make a new request for a new token, but once the new calls are made with the new token, the page resolver doesn't receive the new data. I'm obviously doing something wrong.

private handle401Error(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const currToken = this.authenticationService.getToken();
    if (!this.isRefreshing) {
      this.isRefreshing = true;
      this.refreshTokenSubject.next(null);
      this.httpApiService.getAccessToken(currToken).pipe(
        tap((response: any) => {
          console.log("in refresh", response.body);
          this.authenticationService.setAccessToken(response.body);
        }),
        switchMap((res) => {
          this.isRefreshing = false;
          this.refreshTokenSubject.next(res.body);
            return next.handle(this.addToken(request, res.body));
        })).subscribe()
    } else {
      this.refreshTokenSubject.pipe( 
        filter(token => token != null),
        take(1),
        switchMap(token => {
          console.log("in refreshTokentSubject switchMap", token);
          return next.handle(this.addToken(request, token));
        })).subscribe()
    }
  }
}

RefreshToken Error

Hello, how can I catch the RefreshToken API error and then redirect to the login page.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.