Remove Authorization Header for some http calls Angular
You can use the request.url
property to filter what you need.
One of the easiest ways:
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add authorization header with jwt token if available
const currentUser = this.authenticationService.currentUserValue;
if (request.url.indexOf('some APIs path') === 0 && currentUser && currentUser.token) {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.token}`
}
});
}
return next.handle(request);
}
In those service files use this way
import {HttpBackend, HttpClient} from "@angular/common/http";
constructor(private http: HttpClient, handler: HttpBackend ) {
this.http = new HttpClient(handler);
}