You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @angular/* package(s) are the source of the bug?
common
Is this a regression?
No
Description
I'm using an HttpInterceptor to set the authorization header on requests to our API. When we try to set the header, the interceptor throws from assertValidHeaders.
See this comment for what I agree may be causing the problem: #49353 (comment)
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Unexpected value of the `normalizedNames` header provided. Expecting either a string, a number or an array, but got: `[object Map]`.
The headers object is:
{
"normalizedNames": {},
"lazyUpdate": [
{
"name": "Authorization",
"value": "Bearer <token>",
"op": "s"
}
],
"headers": {},
"lazyInit": {
"normalizedNames": {},
"lazyUpdate": null
}
}
Please provide the environment you discovered this bug in (run ng version)
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor(private authService: AuthenticationService) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.handle(req, next));
}
private async handle(req: HttpRequest<any>, next: HttpHandler): Promise<HttpEvent<any>> {
if (req.url.startsWith(environment.webApiUrl) || req.url.startsWith(environment.adminApiUrl)) {
// Make sure we're authenticated for API calls. These promises will already be complete if we are.
if (!(await this.authService.isAuthenticated())) {
await this.authService.login();
}
// We're now logged in, if we possibly can be.
const accessToken = await this.authService.token();
if (accessToken) {
const cloned = req.clone({
headers: req.headers.set('Authorization', accessToken)
});
console.log(req.headers);
console.log(cloned.headers);
return await lastValueFrom(next.handle(cloned));
}
}
// We'll fall back to here if we couldn't get logged in, and try the request anyway.
return await lastValueFrom(next.handle(req));
}
}
The text was updated successfully, but these errors were encountered:
Which @angular/* package(s) are the source of the bug?
common
Is this a regression?
No
Description
I'm using an HttpInterceptor to set the authorization header on requests to our API. When we try to set the header, the interceptor throws from assertValidHeaders.
See this comment for what I agree may be causing the problem: #49353 (comment)
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Please provide the environment you discovered this bug in (run
ng version)Anything else?
The interceptor:
The text was updated successfully, but these errors were encountered: