Giter Club home page Giter Club logo

boilerplate-angular-django-jwt-login's People

Contributors

maratumba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

boilerplate-angular-django-jwt-login's Issues

Interceptor

Nice boilerplate by the way and thank you for inspiring me on this but I realised that there is something there that is missing (interceptor). You validate for 403 and 401 if the request is the same as the refresh and for 403 if something else but you forgot to validate for a 401 in case the user token is no longer valid but the token is still refreshable (Google recommends a maximum of 200 days for refreshable tokens).

return next.handle(request).pipe(catchError(error => {
      const isRefreshable = this.authService.isRefreshable();
      if ( error instanceof HttpErrorResponse && (error.status === 401 || error.status === 403)
        && request.url === `${environment.apis.v1}/auth/token/refresh`) {
        // We do another check to see if refresh token failed
        // In this case we want to logout user and to redirect it to login page
        // console.log('on your way out')
        this.authService.logout();
        return throwError(error);
      }
      else if (error instanceof HttpErrorResponse && error.status === 403) {
          return this.handle403or401RefreshError(request, next);
      } else if (error instanceof HttpErrorResponse && error.status === 401 && isRefreshable) {
          return this.handle403or401RefreshError(request, next);
      } else {
          return throwError(error);
      }
    }));

Becoming something similar to the above (I renamed the 403 function)

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.