refactor: 로그아웃 및 캐시 정리 로직 개선

- AuthContext 로그아웃 함수를 완전한 캐시 정리 방식으로 개선
- 새로운 logout 유틸리티 추가 (Zustand, sessionStorage, localStorage, 서버 API 통합)
- DashboardLayout → AuthenticatedLayout 이름 변경
- masterDataStore 캐시 정리 기능 강화
- protected 라우트 레이아웃 참조 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
byeongcheolryu
2025-12-15 09:21:43 +09:00
parent c026130a65
commit 8457dba0fc
8 changed files with 277 additions and 31 deletions

View File

@@ -19,6 +19,9 @@ import { fetchPageConfigByType, invalidatePageConfigCache } from '@/lib/api/mast
interface MasterDataStore {
// === State ===
// 현재 테넌트 ID (캐시 격리용)
currentTenantId: number | null;
// 페이지 구성 캐시 (페이지 타입별)
pageConfigs: Record<PageType, PageConfig | null>;
@@ -36,8 +39,12 @@ interface MasterDataStore {
// === Actions ===
// 테넌트 ID 설정 (로그인 시 호출)
setCurrentTenantId: (tenantId: number | null) => void;
// 페이지 구성 가져오기 (하이브리드 로딩)
fetchPageConfig: (pageType: PageType) => Promise<PageConfig | null>;
// tenantId 파라미터는 선택적 (없으면 currentTenantId 사용)
fetchPageConfig: (pageType: PageType, tenantId?: number) => Promise<PageConfig | null>;
// 페이지 구성 캐시 무효화
invalidateConfig: (pageType: PageType) => void;
@@ -365,12 +372,19 @@ export const useMasterDataStore = create<MasterDataStore>()(
// ===== 초기화 =====
reset: () =>
set(
initialState,
false,
'reset'
),
reset: () => {
// 1. 메모리 캐시 초기화
set(initialState, false, 'reset');
// 2. sessionStorage 캐시도 정리
if (typeof window !== 'undefined') {
const pageTypes: PageType[] = ['item-master', 'quotation', 'sales-order', 'formula', 'pricing'];
pageTypes.forEach((pageType) => {
removeConfigFromSessionStorage(pageType);
});
console.log('[masterDataStore] Reset: cleared memory and sessionStorage cache');
}
},
}),
{
name: 'MasterDataStore',