27 lines
653 B
TypeScript
27 lines
653 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> = {
|
|
cookie: document.cookie,
|
|
};
|
|
|
|
if (includeAuth) {
|
|
const header = getAuthHeader();
|
|
if (header != null) {
|
|
headers[header[0]] = header[1];
|
|
}
|
|
}
|
|
|
|
headers['content-type'] = 'application/json';
|
|
|
|
return headers;
|
|
}
|