I am using HttpInterceptor
to add Auth token and the issue is that the interceptor is adding the token for first request and after that it stops working. Here is my Interceptor Service
import { Injectable } from '@angular/core';
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
import {Observable} from "rxjs/internal/Observable";
import {CommonService} from "./common.service";
@Injectable({
providedIn: 'root'
})
export class AuthInterceptorService implements HttpInterceptor {
constructor(private auth: CommonService) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const authToken = this.auth.getAuthToken();
const authReq = req.clone({ setHeaders: { Authorization: 'Bearer '+authToken.access_token} });
return next.handle(authReq);
}
}
Here is the App Module provider section
providers: [{
provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptorService,
multi: true
}],
Let me know what is the wrong with the code.