HTTP interceptor

Implement an HTTP interceptor to inject the JWT into the header of every request sent to the user and also gracefully handle authentication failures by asking the user to log in:

  1. Create authHttpInterceptor under auth:
src/app/auth/auth-http-interceptor.tsimport {  HttpEvent,  HttpHandler,  HttpInterceptor,  HttpRequest,} from '@angular/common/http'import { Injectable } from '@angular/core'import { Router } from '@angular/router'import { Observable, throwError as observableThrowError } from 'rxjs'import { catchError } from 'rxjs/operators'import { AuthService } from './auth.service'@Injectable()export class AuthHttpInterceptor implements HttpInterceptor { constructor(private authService: AuthService, private router: Router) ...

Get Angular 6 for Enterprise-Ready Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.