import { TokenService } from '../token.service' ; import { Injectable } from '@angular/core' ; import { HttpInterceptor , HttpRequest , HttpHandler } from '@angular/common/http' ; @ Injectable ( ) export class JWTInterceptor implements HttpInterceptor { constructor ( private tokenService ) { } intercept ( req , next ) { const authToken = this . tokenService . getAuthorizationToken ( ) ; if ( authToken ) { const authReq = req . clone ( { headers : req . headers . set ( 'Authorization' , `Bearer ${ authToken }` ) } ) ; return next . handle ( authReq ) ; } else { return next . handle ( req ) ; } } }