1
0
mirror of https://github.com/SomboChea/ui synced 2024-11-05 14:14:26 +07:00

fix: token were not being send it

This commit is contained in:
Juan Picado @jotadeveloper 2019-07-28 01:08:15 +02:00
parent a25fc6ec78
commit fd74c52bd1
No known key found for this signature in database
GPG Key ID: 15AA875EF3768142

View File

@ -25,16 +25,16 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string
} }
class API { class API {
public request<T>(url: string, method = 'GET', options?: RequestInit): Promise<T> { public request<T>(url: string, method = 'GET', options: RequestInit = { headers: {} }): Promise<T> {
if (!window.VERDACCIO_API_URL) { if (!window.VERDACCIO_API_URL) {
throw new Error('VERDACCIO_API_URL is not defined!'); throw new Error('VERDACCIO_API_URL is not defined!');
} }
const token = storage.getItem('token'); const token = storage.getItem('token');
const headers = new Headers(options && options.headers); if (token && options.headers && typeof options.headers['Authorization'] === 'undefined') {
if (token && options && options.headers) { options.headers = Object.assign({}, options.headers, {
headers.set('Authorization', `Bearer ${token}`); ['Authorization']: `Bearer ${token}`,
options.headers = Object.assign(options.headers, headers); });
} }
if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) { if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) {