사용자 지역 저장 로직 구현

This commit is contained in:
hyeonsu
2025-08-26 18:33:04 +09:00
parent 11edbb2d18
commit c5fe88a911
2 changed files with 47 additions and 3 deletions

View File

@@ -61,9 +61,29 @@ apiClient.interceptors.request.use(
// 언어 정보를 쿼리 파라미터에 추가 (GET 요청 시에만)
if (config.method?.toUpperCase() === "GET") {
// 전역 언어 상태에서 현재 언어 가져오기 (DB 값 그대로 사용)
const currentLang = typeof window !== "undefined" ? (window as any).__GLOBAL_USER_LANG || "KR" : "KR";
console.log("🌐 API 요청 시 언어 정보:", currentLang);
// 우선순위: 전역 변수 > localStorage > 기본값
let currentLang = "KR"; // 기본값
if (typeof window !== "undefined") {
// 1순위: 전역 변수에서 확인
if ((window as any).__GLOBAL_USER_LANG) {
currentLang = (window as any).__GLOBAL_USER_LANG;
}
// 2순위: localStorage에서 확인 (새 창이나 페이지 새로고침 시)
else {
const storedLocale = localStorage.getItem("userLocale");
if (storedLocale) {
currentLang = storedLocale;
}
}
}
console.log("🌐 API 요청 시 언어 정보:", {
currentLang,
globalVar: (window as any).__GLOBAL_USER_LANG,
localStorage: typeof window !== "undefined" ? localStorage.getItem("userLocale") : null,
url: config.url,
});
if (config.params) {
config.params.userLang = currentLang;