I have a go web server to which I am sending requests from my application. I have written an HTTP interceptor in order to attach the auth token given by firebase so I can validate it on my go web server. For some reason, the interceptor doesn't appear to be changing the headers of the request to attach the auth token.
intercept(req: HttpRequest<any>, next: HttpHandler){
return from(this.auth.auth.currentUser.getIdToken()).pipe(switchMap(token => {
if(token){
const authReq = req.clone({
setHeaders: {
'Content-Type': 'application/json',
Authorization: token,
'Access-Control-Allow-Origin': '*'
}
});
return next.handle(authReq);
}
return next.handle(req);
})
);
return next.handle(req);
}
This within a service called AuthHandler which implements HTTPInterceptor. Any help would be appreciated! I am on angularfire version 5.4 and angular9
Turns out my problem wasn't with firebase but rather setting up the interceptor. This link is very useful. Essentially you have to include the service class in the providers section of the app module.
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
(...)
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: MyInterceptor, multi: true }
],