Posts

Showing posts from January 7, 2019

angular 6 interceptor is called after request is sent

Image
1 I'm working on an angular 6 app where I want to add an jwt-token to the authorize-header of every request. For this scenario I want to use an interceptor. The code looks like this: import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from "@angular/common/http"; import { Injectable } from "@angular/core"; import { Observable } from "rxjs"; @Injectable() export class AuthInterceptor implements HttpInterceptor { intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { let sessionId = localStorage.getItem('sessionId'); if (sessionId) { request = request.clone({ setHeaders: { Authorization: `Bearer ${sessionId}` } }); console.log(&