HTTP 拦截器不发送 firebase 身份验证令牌

HTTP Interceptor not sending firebase auth token

我有一个 go web 服务器,我正在向其发送来自我的应用程序的请求。我编写了一个 HTTP 拦截器以附加 firebase 提供的身份验证令牌,以便我可以在我的 go web 服务器上验证它。出于某种原因,拦截器似乎没有更改请求的 headers 以附加身份验证令牌。

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);
    }

这在一个名为 AuthHandler 的服务中,它实现了 HTTPInterceptor。任何帮助,将不胜感激!我使用的是 angularfire 5.4 版和 angular9

事实证明,我的问题不在于 firebase,而在于设置拦截器。这个很有用。本质上,您必须在应用程序模块的提供程序部分包含服务 class。

import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
(...)
  providers: [
    { provide: HTTP_INTERCEPTORS, useClass: MyInterceptor, multi: true }
  ],