23 lines
574 B
TypeScript
23 lines
574 B
TypeScript
import Cookies from "js-cookie";
|
|
import { getConfig } from "@common/config";
|
|
|
|
export function getAuthHeaders(): HeadersInit {
|
|
const { CLAIM_NAME, AUTH_USER_ID } = getConfig();
|
|
|
|
if (!CLAIM_NAME || !AUTH_USER_ID) {
|
|
throw new Error("Required environment variables are not set");
|
|
}
|
|
|
|
const headers: Record<string, string> = {
|
|
"Content-Type": "application/json",
|
|
};
|
|
|
|
const token = Cookies.get(CLAIM_NAME);
|
|
const userId = Cookies.get(AUTH_USER_ID);
|
|
|
|
if (token) headers[CLAIM_NAME] = token;
|
|
if (userId) headers[AUTH_USER_ID] = userId;
|
|
|
|
return headers;
|
|
}
|