From fd74c52bd1f67178c4a404dd0114282e6be67c7f Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Sun, 28 Jul 2019 01:08:15 +0200 Subject: [PATCH] fix: token were not being send it --- src/utils/api.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/api.ts b/src/utils/api.ts index 4713fc5..eec6396 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -25,16 +25,16 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string } class API { - public request(url: string, method = 'GET', options?: RequestInit): Promise { + public request(url: string, method = 'GET', options: RequestInit = { headers: {} }): Promise { if (!window.VERDACCIO_API_URL) { throw new Error('VERDACCIO_API_URL is not defined!'); } const token = storage.getItem('token'); - const headers = new Headers(options && options.headers); - if (token && options && options.headers) { - headers.set('Authorization', `Bearer ${token}`); - options.headers = Object.assign(options.headers, headers); + if (token && options.headers && typeof options.headers['Authorization'] === 'undefined') { + options.headers = Object.assign({}, options.headers, { + ['Authorization']: `Bearer ${token}`, + }); } if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) {