[as frontend] device-id 추가후 테스트

This commit is contained in:
2026-07-08 10:45:53 +09:00
parent 774f3a5507
commit c41a7bf3d3
2 changed files with 43 additions and 0 deletions
+15
View File
@@ -20,6 +20,16 @@ async function handler(
"Content-Type": "application/json",
"X-Site-Id": SITE_ID,
};
// X-Device-Id 중계 로직 (헤더 또는 쿠키에서 획득)
const deviceId =
request.headers.get("x-device-id") ||
request.headers.get("X-Device-Id") ||
cookieStore.get("device-id")?.value;
if (deviceId) {
headers["X-Device-Id"] = deviceId;
}
let body = {};
const isRefreshHandler = params.url.includes("refresh");
@@ -45,6 +55,11 @@ async function handler(
});
if (!result.ok) {
console.error(`[BFF Proxy Error] Backend returned status ${result.status} for ${params.url.join("/")}`);
try {
const errorText = await result.text();
console.error(`[BFF Proxy Error Body] ${errorText}`);
} catch (err) {}
return NextResponse.json(
{ message: "Invalid Credentials" },
{ status: 401 },
+28
View File
@@ -24,6 +24,21 @@ class Client {
});
this.axiosInstance.interceptors.request.use((config) => {
// X-Device-Id 자동 주입 로직 (기기에 고유한 UUID 세팅 및 쿠키/로컬스토리지 보관)
let deviceId = Cookies.get("device-id");
if (!deviceId && typeof window !== "undefined") {
deviceId = localStorage.getItem("device-id") || undefined;
if (!deviceId) {
deviceId = generateUUID();
localStorage.setItem("device-id", deviceId);
}
Cookies.set("device-id", deviceId, { expires: 365, path: "/" });
}
if (deviceId) {
config.headers["X-Device-Id"] = deviceId;
}
const token = Cookies.get(CLAIM_NAME);
const userId = Cookies.get(AUTH_USER_ID);
@@ -87,3 +102,16 @@ class Client {
export type { ClientConfig };
export { Client };
// 기기 식별을 위한 안전한 v4 UUID 생성 폴백 헬퍼 함수
function generateUUID(): string {
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0;
const v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}