0

I try to hang jwt web token to my outgoing request, I used interceptor approach after the adding interceptor "ERROR TypeError: Cannot read property 'length' of undefined" is shown. when interceptor file is removed app work correctly This is my dev console

this is my intercept class

interceptor

1 Answers1

0

This is a simplified version but it works like a charm in my app:

public intercept(
            req: HttpRequest<any>,
            next: HttpHandler
        ): Observable<HttpEvent<any>> {

        req = this.addAuthHeader(req);
    }

    addAuthHeader(request) {
         const r: HttpRequest<any> = request.clone({
             headers: new HttpHeaders({
                    Authorization: 'Bearer ' + this.authService.getToken()
             })
         });
         return r;
    }

for reference --> how-to-add-multiple-headers-in-angular-5-httpinterceptor and interceptor-angular-4-3-set-multiple-headers-on-the-cloned-request

regards

sagat
  • 1,351
  • 12
  • 15