import { Injectable } from '@angular/core' ; import { HttpInterceptor , HttpXsrfTokenExtractor , HttpRequest , HttpHandler , HttpEvent } from '@angular/common/http' ; import { Observable } from 'rxjs' ; @ Injectable ( ) export class HttpXsrfInterceptor implements HttpInterceptor { constructor ( private tokenExtractor ) { } intercept ( req , next ) { const headerName = 'x-xsrf-token' ; let token = this . tokenExtractor . getToken ( ) as string ; if ( token !== null && ! req . headers . has ( headerName ) ) { req = req . clone ( { headers : req . headers . set ( headerName , token ) } ) ; } return next . handle ( req ) ; } }