import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor } from '@angular/common/http' ; import { Observable } from 'rxjs' ; import { LocalStorageService } from '../services/local-storage.service' ; @ Injectable ( ) export class AuthInterceptor implements HttpInterceptor { constructor ( private localStorageService ) { } intercept ( request , next ) { let token = this . localStorageService . getToken ( ) ; let newRequest ; newRequest = request . clone ( { headers : request . headers . set ( "Authorization" , "Bearer " + token ) } ) ; return next . handle ( newRequest ) ; } }