[common/components] feat: raw fetch 헤더에 토큰 주입
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user