diff --git a/frontend/src/api/axiosConfig.ts b/frontend/src/api/axiosConfig.ts index 5a0489a..adb3d4e 100644 --- a/frontend/src/api/axiosConfig.ts +++ b/frontend/src/api/axiosConfig.ts @@ -30,7 +30,7 @@ const processQueue = (error: Error | null, token: string | undefined = undefined }; api.interceptors.request.use((config: InternalAxiosRequestConfig) => { - const token = localStorage.getItem('accessToken'); + const token = sessionStorage.getItem('accessToken'); if (token && config.headers) { config.headers.Authorization = `Bearer ${token}`; } @@ -72,7 +72,7 @@ api.interceptors.response.use( } useAuthStore.getState().setLoggedIn(true, newAccessToken); - localStorage.setItem('accessToken', newAccessToken); + sessionStorage.setItem('accessToken', newAccessToken); processQueue(null, newAccessToken); if (originalRequest.headers) { diff --git a/frontend/src/stores/useAuthStore.ts b/frontend/src/stores/useAuthStore.ts index 2512c3f..61bff9f 100644 --- a/frontend/src/stores/useAuthStore.ts +++ b/frontend/src/stores/useAuthStore.ts @@ -1,18 +1,13 @@ import { create } from 'zustand'; import { persist } from 'zustand/middleware'; - -interface ProfileData { - id: number | null; - nickname: string; - profileImage: string; -} +import { MemberResponseDTO } from '@/types'; interface AuthState { isLoggedIn: boolean; accessToken: string; - profile: ProfileData; + profile: MemberResponseDTO | null; setLoggedIn: (status: boolean, token: string) => void; - setProfile: (profile: ProfileData) => void; + setProfile: (profile: MemberResponseDTO) => void; clearAuth: () => void; } @@ -21,15 +16,14 @@ const useAuthStore = create()( (set) => ({ isLoggedIn: false, accessToken: '', - profile: { id: null, nickname: '', profileImage: '' }, + profile: null, setLoggedIn: (status, token) => set({ isLoggedIn: status, accessToken: token }), setProfile: (profile) => set({ profile }), - clearAuth: () => - set({ isLoggedIn: false, accessToken: '', profile: { id: null, nickname: '', profileImage: '' } }), + clearAuth: () => set({ isLoggedIn: false, accessToken: '', profile: null }), }), { name: 'auth-storage', - getStorage: () => localStorage, + getStorage: () => sessionStorage, } ) );