import { Injectable } from '@angular/core' ; import { HttpRequest , HttpHandler , HttpEvent , HttpInterceptor } from '@angular/common/http' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { User } from '../../management/models/user' ; import { Token } from '../models/token' ; @ Injectable ( ) export class BasicAuthInterceptor implements HttpInterceptor { public intercept ( request , next ) { const currentUser = new BehaviorSubject < User > ( JSON . parse ( localStorage . getItem ( 'current-user' ) ) ) . value ; const currentUserToken = new BehaviorSubject < Token > ( JSON . parse ( localStorage . getItem ( 'access-token' ) ) ) . value ; if ( currentUser && currentUserToken ) { request = request . clone ( { setHeaders : { Authorization : `Bearer ${ currentUserToken . token }` , 'Cache-Control' : 'no-cache' , Pragma : 'no-cache' } } ) ; } return next . handle ( request ) ; } }