fix: error "Request cannot be constructed from a URL that includes credentials" after 'basic' login

Massimo Melina committed Jun 16, 2024 at 23:46 UTC ed5a5c92c410a4aa3c0b12e43af42c3e17ad3201
1 file changed +2 -1
shared/api.ts
+2 -1
@@ -37,7 +37,8 @@ export function apiCall<T=any>(cmd: string, params?: Dict, options: ApiCallOptio
37 controller.abort(aborted = 'timeout')
38 console.debug('API TIMEOUT', cmd, params??'')
39 }, ms)
40 - return Object.assign(fetch(getPrefixUrl() + API_URL + cmd, {
40 + const l = location // rebuilding the whole url makes it resistant to url-with-credentials
41 + return Object.assign(fetch(`${l.protocol}//${l.host}${getPrefixUrl()}${API_URL}${cmd}`, {
42 method: options.method || 'POST',
43 headers: { 'content-type': 'application/json', 'x-hfs-anti-csrf': '1' },
44 signal: controller.signal,