Git Product home page Git Product logo

angular-8-jwt-authentication's Introduction

Angular 8 JWT Authentication example

Flow for User Registration and User Login

For JWT – Token based Authentication with Web API, we’re gonna call 2 endpoints:

  • POST api/auth/signup for User Registration
  • POST api/auth/signin for User Login

You can take a look at following flow to have an overview of Requests and Responses that Angular 10 Client will make or receive.

angular-8-jwt-authentication-flow

Angular JWT App Diagram with Router and HttpInterceptor

angular-8-jwt-authentication-overview

For more detail, please visit:

Angular 8 JWT Authentication with Web API

Angular 10 JWT Authentication with Web API

With Spring Boot back-end

Angular 8 + Spring Boot: JWT Authentication & Authorization example

Angular 10 + Spring Boot: JWT Authentication & Authorization example

Run ng serve for a dev server. Navigate to http://localhost:4200/.

With Node.js Express back-end

Node.js Express + Angular 8: JWT Authentication & Authorization example

Node.js Express + Angular 10: JWT Authentication & Authorization example

Open app/_helpers/auth.interceptor.js, modify the code to work with x-access-token like this:

...

// const TOKEN_HEADER_KEY = 'Authorization'; // for Spring Boot back-end
const TOKEN_HEADER_KEY = 'x-access-token';   // for Node.js Express back-end

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
  ...

  intercept(req: HttpRequest<any>, next: HttpHandler) {
    ...
    if (token != null) {
      // for Spring Boot back-end
      // authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, 'Bearer ' + token) });

      // for Node.js Express back-end
      authReq = req.clone({ headers: req.headers.set(TOKEN_HEADER_KEY, token) });
    }
    return next.handle(authReq);
  }
}

...

Run ng serve --port 8081 for a dev server. Navigate to http://localhost:8081/.

More Practice

Angular 8 CRUD application example with Web API

Angular 8 Pagination example | ngx-pagination

Angular 8 Multiple Files upload example

Fullstack with Node.js Express:

Angular 8 + Node.js Express + MySQL

Angular 8 + Node.js Express + PostgreSQL

Angular 8 + Node.js Express + MongoDB

Fullstack with Spring Boot:

Angular 8 + Spring Boot + MySQL

Angular 8 + Spring Boot + PostgreSQL

Angular 8 + Spring Boot + MongoDB

Fullstack with Django:

Angular 8 + Django Rest Framework

angular-8-jwt-authentication's People

Contributors

tienbku 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

angular-8-jwt-authentication's Issues

Role user registration form

Hi, can you show how we can create user in registration form in specific role. Now when we create user it is always have user role.

Could you show models package?

Hi, in your video you had user.model.ts file(guess with user class?)

In my app.component.ts I have errors with user.roles, user.username because its:
TS2339: Property 'roles' does not exist on type 'string'.
TS2339: Property 'username' does not exist on type 'string'.

Could you help pls?

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.