Add basic authentication

This commit is contained in:
2026-05-02 14:59:05 +02:00
parent e1c6ea9e51
commit f1fd72520a
15 changed files with 369 additions and 66 deletions
+17
View File
@@ -5,3 +5,20 @@ export const makeApiUrl = (endpoint: string) => {
const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`;
return `${base}${path}`;
};
export const authHeaders = () => {
try {
const token = localStorage.getItem('token');
return token ? { Authorization: `Bearer ${token}` } : {};
} catch (e) {
return {};
}
};
export const fetchWithAuth = (endpoint: string, options: RequestInit = {}) => {
const headers = {
...(options.headers || {}),
...authHeaders(),
} as Record<string, string>;
return fetch(makeApiUrl(endpoint), { ...options, headers });
};