import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor } from '@angular/common/http' ; import { Observable } from 'rxjs' ; @ Injectable ( ) export class JwtInterceptor implements HttpInterceptor { intercept ( request , next ) { let currentUser = JSON . parse ( localStorage . getItem ( 'currentUser' ) || '{}' ) ; if ( currentUser && currentUser . token ) { request = request . clone ( { setHeaders : { Authorization : `Bearer ${ currentUser . token }` } } ) ; } return next . handle ( request ) ; } }