start frant 050228
This commit is contained in:
+7
-2
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user