diff --git a/src/api/api.ts b/src/api/api.ts index 113549c..1e12e4c 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,4 +1,5 @@ import axios from 'axios'; +import { useAuthStore } from '@/store/auth.store'; const api = axios.create({ baseURL: process.env.NEXT_PUBLIC_BASE_URL, @@ -70,8 +71,7 @@ api.interceptors.response.use( } catch (refreshError) { // refreshToken도 만료되었거나 재발급 실패 console.error('토큰 재발급 실패:', refreshError); - localStorage.removeItem('accessToken'); - localStorage.removeItem('refreshToken'); + useAuthStore.getState().logout(); throw refreshError; } finally { // 재발급 완료 후 Promise 초기화 (성공/실패 관계없이) @@ -94,6 +94,7 @@ api.interceptors.response.use( } console.error('인증이 만료되었습니다. 다시 로그인하세요.'); + useAuthStore.getState().logout(); } return Promise.reject(error); } diff --git a/src/app/_components/common/Header.tsx b/src/app/_components/common/Header.tsx index fd2e35f..d9b61c6 100644 --- a/src/app/_components/common/Header.tsx +++ b/src/app/_components/common/Header.tsx @@ -80,9 +80,7 @@ const Header = () => { const handleLogout = () => { logout(); - clearUser(); router.push('/'); - setIsProfileOpen(false); }; @@ -134,12 +132,24 @@ const Header = () => { href="/business" className={dropdownItem} role="menuitem" + onClick={(e) => { + if (!isAuthenticated) { + e.preventDefault(); + setOpenLogin(true); + } + }} > 작성하기 + setOpenLogin(false)} /> ); }; diff --git a/src/store/user.store.ts b/src/store/user.store.ts index 08c49bc..e0c5570 100644 --- a/src/store/user.store.ts +++ b/src/store/user.store.ts @@ -38,6 +38,7 @@ export const useUserStore = create()( } } catch (error) { console.error('유저를 찾을 수 없습니다', error); + set({ user: null }); } }, }), diff --git a/tsconfig.json b/tsconfig.json index a966197..2b452a7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,11 @@ { "compilerOptions": { "target": "ES2017", - "lib": ["dom", "dom.iterable", "esnext"], + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], "allowJs": true, "skipLibCheck": true, "strict": true, @@ -11,7 +15,7 @@ "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, - "jsx": "preserve", + "jsx": "react-jsx", "incremental": true, "plugins": [ { @@ -20,7 +24,9 @@ ], "baseUrl": ".", "paths": { - "@/*": ["src/*"] + "@/*": [ + "src/*" + ] } }, "include": [ @@ -30,5 +36,7 @@ ".next/types/**/*.ts", ".next/dev/types/**/*.ts" ], - "exclude": ["node_modules"] + "exclude": [ + "node_modules" + ] }