1
0
mirror of https://github.com/SomboChea/ui synced 2024-12-25 05:34: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 {
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) {
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))) {