forked from sombochea/verdaccio-ui
fix: token were not being send it
This commit is contained in:
parent
a25fc6ec78
commit
fd74c52bd1
@ -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))) {
|
||||||
|
Loading…
Reference in New Issue
Block a user