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

Commit fd74c52

Browse files
committed
fix: token were not being send it
1 parent a25fc6e commit fd74c52

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/utils/api.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string
2525
}
2626

2727
class API {
28-
public request<T>(url: string, method = 'GET', options?: RequestInit): Promise<T> {
28+
public request<T>(url: string, method = 'GET', options: RequestInit = { headers: {} }): Promise<T> {
2929
if (!window.VERDACCIO_API_URL) {
3030
throw new Error('VERDACCIO_API_URL is not defined!');
3131
}
3232

3333
const token = storage.getItem('token');
34-
const headers = new Headers(options && options.headers);
35-
if (token && options && options.headers) {
36-
headers.set('Authorization', `Bearer ${token}`);
37-
options.headers = Object.assign(options.headers, headers);
34+
if (token && options.headers && typeof options.headers['Authorization'] === 'undefined') {
35+
options.headers = Object.assign({}, options.headers, {
36+
['Authorization']: `Bearer ${token}`,
37+
});
3838
}
3939

4040
if (!['http://', 'https://', '//'].some(prefix => url.startsWith(prefix))) {

0 commit comments

Comments
 (0)