angular-11-jwt-authentication
angular-11-jwt-authentication copied to clipboard
Angular 11 JWT Authentication & Authorization example with Web API
Angular 11 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/signupfor User Registration - POST
api/auth/signinfor 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 JWT App Diagram with Router and HttpInterceptor

For more detail, please visit:
With Spring Boot back-end
Angular + Spring Boot: JWT Authentication & Authorization example
Run ng serve for a dev server. Navigate to http://localhost:4200/.
With Node.js Express back-end
Angular + Node.js Express: 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): Observable<HttpEvent<any>> {
...
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
Fullstack with Node.js Express:
Angular 11 + Node.js Express: JWT Authentication & Authorization example
Fullstack with Spring Boot:
Angular 11 + Spring Boot: JWT Authentication & Authorization example
Fullstack with Django:
Serverless with Firebase:
Integration (run back-end & front-end on same server/port)