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

@@ -1,6 +1,7 @@
'use client';
import { createContext, useContext, useState, useEffect, useRef, ReactNode } from 'react';
import { performFullLogout } from '@/lib/auth/logout';
// ===== 타입 정의 =====
@@ -54,7 +55,7 @@ interface AuthContextType {
updateUser: (userId: string, updates: Partial<User>) => void;
deleteUser: (userId: string) => void;
getUserByUserId: (userId: string) => User | undefined;
logout: () => void; // ✅ 추가: 로그아웃
logout: () => Promise<void>; // ✅ 추가: 로그아웃 (완전한 캐시 정리)
clearTenantCache: (tenantId: number) => void; // ✅ 추가: 테넌트 캐시 삭제
resetAllData: () => void;
}
@@ -224,14 +225,20 @@ export function AuthProvider({ children }: { children: ReactNode }) {
});
};
// ✅ 추가: 로그아웃 함수
const logout = () => {
if (currentUser?.tenant?.id) {
clearTenantCache(currentUser.tenant.id);
}
// ✅ 추가: 로그아웃 함수 (완전한 캐시 정리)
const logout = async () => {
console.log('[Auth] Starting logout...');
// 1. React 상태 초기화 (UI 즉시 반영)
setCurrentUser(null);
localStorage.removeItem('mes-currentUser');
console.log('[Auth] Logged out and cleared tenant cache');
// 2. 완전한 로그아웃 수행 (Zustand, sessionStorage, localStorage, 서버 API)
await performFullLogout({
skipServerLogout: false, // 서버 API 호출 (HttpOnly 쿠키 삭제)
redirectTo: null, // 리다이렉트는 호출하는 곳에서 처리
});
console.log('[Auth] Logout completed');
};
// Context value