Angular AuthHttpInterceptor option for adding headers to every request

I just implemented Auth0 in an existing angular project that used token based authentication in the past. There was a custom-made interceptor.service.ts that was replaced with the default auth0 AuthHttpInterceptor.

This works great, but I noticed some API calls were failing. The issue was that the old interceptor service added

“Content-Type”: “application/json”

by default, like this:

let tokenizedReq = req.clone({
     setHeaders: {
        Authorization: `Bearer ${authenticationService.getToken()}`,
        "Content-Type": "application/json",
     },
});

I know that I can add headers to requests individually, but I would rather have the Auth0 service take care of that by default. I would have to refactor every http service method if I were to go that route. Is there any way to configure the AuthHttpInterceptor in this way?

Thanks!

1 Like