I have made authorization which puts the token to headers directly. How can I now get this token from Angular 4 Http Interceptor?

Unfortunately none of below console logs includes this header:
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
//const changedReq = req.clone({headers: req.headers.set('Authorization', 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbkB3cC5wbCIsImV4cCI6MTUxMDY2NDM0M30.0iBktdr4-1EzTi1iaQOOfguK7HGVJF7JYkB-AF3uZgJrmKnVESAyKkHoNRzum1Pq5xZ6GJaZC9cbZQ2umMSfLA')});
console.log('req', req);
return next.handle(req).do((event: HttpEvent<any>) => {
console.log('event', event);
if (event instanceof HttpResponse) {
// do stuff with response if you want
}
}, (err: any) => {
if (err instanceof HttpErrorResponse) {
this.ehs.setService(err.status, err.error);
// redirect to login
}
});
}
HttpHeaders is a wrapper for Map instance, so existing headers won't be displayed in console.log output, because Map values aren't exposed.
Headers can be retrieved from HttpHeaders instance, as its API suggests:
req.headers.get('authorization');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With