From 563257930c8a4fc21c557b5dff4af9d72edfb19e Mon Sep 17 00:00:00 2001 From: "fabio.formosa" Date: Sat, 2 May 2020 16:52:20 +0200 Subject: [PATCH] #6 fixed authorization header set --- .../src/app/services/api.service.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/quartz-manager-frontend/src/app/services/api.service.ts b/quartz-manager-frontend/src/app/services/api.service.ts index 4c4ae29..6760f30 100644 --- a/quartz-manager-frontend/src/app/services/api.service.ts +++ b/quartz-manager-frontend/src/app/services/api.service.ts @@ -70,20 +70,23 @@ export class ApiService { } private request(path: string, body: any, method = RequestMethod.Post, customHeaders?: HttpHeaders): Observable { - const req = new HttpRequest(method, path, body, { + const options = { headers: customHeaders || this.headers, withCredentials: true - }); + } if(this.jwtToken) - req.headers.append('Authorization', `Bearer ${this.jwtToken}`); + options.headers = options.headers.append('Authorization', `Bearer ${this.jwtToken}`); + + const req = new HttpRequest(method, path, body, options); return this.http.request(req) .pipe( filter(response => response instanceof HttpResponse), tap((resp: HttpResponse) => { let jwtToken = ApiService.extractTokenFromHttpResponse(resp); - this.setToken(jwtToken); + if(jwtToken) + this.setToken(jwtToken); }), map((response: HttpResponse) => response.body), catchError(error => this.checkError(error))