start frant 050228

This commit is contained in:
2026-05-18 20:18:28 +03:30
parent 26e59e03e0
commit cb65e5e601
33 changed files with 1493 additions and 425 deletions
+7 -2
View File
@@ -14,14 +14,19 @@ type ApiOptions = RequestInit & {
token?: string;
};
export function getApiToken(): string | null {
return localStorage.getItem('montime_access_token');
}
export async function api<T>(path: string, options: ApiOptions = {}): Promise<T> {
const token = options.token ?? getApiToken() ?? undefined;
const headers: Record<string, string> = {
'Content-Type': 'application/json',
...(options.headers as Record<string, string> | undefined),
};
if (options.token) {
headers.Authorization = `Bearer ${options.token}`;
if (token) {
headers.Authorization = `Bearer ${token}`;
}
const { token: _token, ...fetchOptions } = options;