fix(WEB): 마스터데이터 캐시 테넌트 격리 및 상세 템플릿 개선

- masterDataStore: 테넌트별 캐시 격리 로직 강화
- AuthContext: 인증 컨텍스트 안정성 개선
- IntegratedDetailTemplate: 상세 템플릿 동작 수정
- VendorDetail: 거래처 상세 수정
- AttendanceManagement: 타입 정의 추가

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
유병철
2026-01-29 16:57:49 +09:00
parent 4014b3fb84
commit 106ce09482
7 changed files with 211 additions and 29 deletions

View File

@@ -2,6 +2,7 @@
import { createContext, useContext, useState, useEffect, useRef, ReactNode } from 'react';
import { performFullLogout } from '@/lib/auth/logout';
import { useMasterDataStore } from '@/stores/masterDataStore';
// ===== 타입 정의 =====
@@ -201,24 +202,31 @@ export function AuthProvider({ children }: { children: ReactNode }) {
previousTenantIdRef.current = currentTenantId || null;
}, [currentUser?.tenant?.id]);
// ✅ 추가: masterDataStore에 현재 테넌트 ID 동기화
useEffect(() => {
const tenantId = currentUser?.tenant?.id ?? null;
useMasterDataStore.getState().setCurrentTenantId(tenantId);
}, [currentUser?.tenant?.id]);
// ✅ 추가: 테넌트별 캐시 삭제 함수 (SSR-safe)
const clearTenantCache = (tenantId: number) => {
// 서버 환경에서는 실행 안함
if (typeof window === 'undefined') return;
const prefix = `mes-${tenantId}-`;
const tenantAwarePrefix = `mes-${tenantId}-`;
const pageConfigPrefix = `page_config_${tenantId}_`;
// localStorage 캐시 삭제
Object.keys(localStorage).forEach(key => {
if (key.startsWith(prefix)) {
if (key.startsWith(tenantAwarePrefix)) {
localStorage.removeItem(key);
console.log(`[Cache] Cleared localStorage: ${key}`);
}
});
// sessionStorage 캐시 삭제
// sessionStorage 캐시 삭제 (TenantAwareCache + masterDataStore)
Object.keys(sessionStorage).forEach(key => {
if (key.startsWith(prefix)) {
if (key.startsWith(tenantAwarePrefix) || key.startsWith(pageConfigPrefix)) {
sessionStorage.removeItem(key);
console.log(`[Cache] Cleared sessionStorage: ${key}`);
}