사용자 지역 저장 로직 구현
This commit is contained in:
parent
11edbb2d18
commit
c5fe88a911
|
|
@ -49,6 +49,30 @@ export function MenuProvider({ children }: { children: ReactNode }) {
|
|||
setLoading(true);
|
||||
console.log("=== MenuContext API 호출 시작 ===");
|
||||
|
||||
// 사용자 로케일이 로드될 때까지 잠시 대기
|
||||
let retryCount = 0;
|
||||
const maxRetries = 20; // 최대 2초 대기 (100ms * 20)
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
if (typeof window !== "undefined") {
|
||||
const hasGlobalLang = !!(window as any).__GLOBAL_USER_LANG;
|
||||
const hasStoredLang = !!localStorage.getItem("userLocale");
|
||||
|
||||
if (hasGlobalLang || hasStoredLang) {
|
||||
console.log("✅ 사용자 로케일 로드 완료, 메뉴 API 호출 진행");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`⏳ 사용자 로케일 로드 대기 중... (${retryCount + 1}/${maxRetries})`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
retryCount++;
|
||||
}
|
||||
|
||||
if (retryCount >= maxRetries) {
|
||||
console.warn("⚠️ 사용자 로케일 로드 타임아웃, 기본값으로 진행");
|
||||
}
|
||||
|
||||
// 관리자 메뉴와 사용자 메뉴를 병렬로 로드
|
||||
const [adminResponse, userResponse] = await Promise.all([menuApi.getAdminMenus(), menuApi.getUserMenus()]);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue