Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
fix: token were not being send it
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpicado committed Jul 28, 2019
1 parent a25fc6e commit fd74c52
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down

0 comments on commit fd74c52

Please sign in to comment.