I have created a custom authentication interceptor which implements HttpInterceptor. I will be adding headers to the every request I make with httpClient. Now I have few requests which don't need authentication headers to be added.
Below is the code of my custom interceptor for reference
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private franchiserService: FranchiserService,
private currentMerchantService: CurrentMerchantService) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpSentEvent | HttpHeaderResponse | HttpProgressEvent | HttpResponse<any> | HttpUserEvent<any>> {
console.log('Request Intercepted');
const franchiserKey = this.franchiserService.franchiser.apiKey;
const merchantKey = this.currentMerchantService.merchant.apiKey;
const authReq = req.clone({
headers: req.headers.append('franchiserKey', franchiserKey).append('merchantKey', merchantKey),
url: environment.origin + req.url
});
return next.handle(authReq);
}
}
How I can implement custom interceptor which can do the both?