Files
warren/frontend/lib/api/index.ts
2025-07-21 09:37:53 +02:00

25 lines
615 B
TypeScript

export function getAuthHeader(): ['authorization', string] | null {
const authSession = useAuthSession().value;
if (authSession == null) {
return null;
}
return ['authorization', `${authSession.type} ${authSession.id}`];
}
export function getApiHeaders(
includeAuth: boolean = true
): Record<string, string> {
const headers: Record<string, string> = {};
if (includeAuth) {
const header = getAuthHeader();
if (header != null) {
headers[header[0]] = header[1];
}
}
headers['content-type'] = 'application/json';
return headers;
}