Skip to content

Commit 1da2e53

Browse files
fmellharalde
authored andcommitted
Only set Authorization header if token was fetched
1 parent aefda53 commit 1da2e53

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

frontend/src/api/api.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ async function apiRequest<Model extends z.ZodTypeAny>(
6363

6464
const body = init.body ?? (init.json !== undefined ? JSON.stringify(init.json) : undefined);
6565

66-
const headers = {
66+
const headers: Record<string, string> = {
6767
"Content-Type": "application/json",
68-
Authorization: `Bearer ${token}`,
69-
...(init.headers ?? {}),
68+
...Object.fromEntries(new Headers(init.headers as HeadersInit)),
7069
};
70+
if (token) {
71+
headers["Authorization"] = `Bearer ${token}`;
72+
}
7173

7274
const response = await fetch(url, {
7375
...init,

0 commit comments

Comments
 (0)