I try to use an angular injector to add a bearer token
although the code is executed, the header is not added
there are many different codes out there, I tried some of them, they all lead to the same issue
no bearer is send with the request
in the below image I stopped at clone/headers.set, but even after that step, the headers map is still empty
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(
private appService: AppService
) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// add auth header with jwt if user is logged in and request is to the api url
let authentication: Authentication = this.appService.getUserSession();
const isLoggedIn = authentication && authentication.token;
const isApiUrl = request.url.startsWith(environment.apiUrl);
//------------------------------------- add id's
let body = request.body;
if(!body)
{
body={};
}
body['clientId'] = environment.clientId;
body['clientSecret'] = environment.clientSecret;
request = request.clone({
body: body
});
//--------------------------------------- add jwt
if(authentication)
{
request = request.clone(
{
headers: request.headers.set('Bearer', authentication.token)
}
);
}
return next.handle(request);
}
}
thanks for helping me on this one
