From 07cbe72ba995261de3e9710342d90d411c83092a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=98=84=EC=A1=B0?= Date: Thu, 12 Sep 2024 10:54:21 +0900 Subject: [PATCH] =?UTF-8?q?Refactor:=20api,=20=EC=84=B8=EC=85=98=20?= =?UTF-8?q?=EC=8A=A4=ED=86=A0=EB=A6=AC=EC=A7=80=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/axiosConfig.ts | 4 ++-- frontend/src/stores/useAuthStore.ts | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) 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, } ) );