May 2018
Intermediate to advanced
512 pages
11h 3m
English
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:
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) ...Read now
Unlock full access