From e054f320b7b06e74505df7897a9ff9968b652e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=ED=98=84=EC=A1=B0?= Date: Wed, 11 Sep 2024 13:38:45 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20useAuthStore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/stores/useAuthStore.ts | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 frontend/src/stores/useAuthStore.ts diff --git a/frontend/src/stores/useAuthStore.ts b/frontend/src/stores/useAuthStore.ts new file mode 100644 index 0000000..2512c3f --- /dev/null +++ b/frontend/src/stores/useAuthStore.ts @@ -0,0 +1,37 @@ +import { create } from 'zustand'; +import { persist } from 'zustand/middleware'; + +interface ProfileData { + id: number | null; + nickname: string; + profileImage: string; +} + +interface AuthState { + isLoggedIn: boolean; + accessToken: string; + profile: ProfileData; + setLoggedIn: (status: boolean, token: string) => void; + setProfile: (profile: ProfileData) => void; + clearAuth: () => void; +} + +const useAuthStore = create()( + persist( + (set) => ({ + isLoggedIn: false, + accessToken: '', + profile: { id: null, nickname: '', profileImage: '' }, + setLoggedIn: (status, token) => set({ isLoggedIn: status, accessToken: token }), + setProfile: (profile) => set({ profile }), + clearAuth: () => + set({ isLoggedIn: false, accessToken: '', profile: { id: null, nickname: '', profileImage: '' } }), + }), + { + name: 'auth-storage', + getStorage: () => localStorage, + } + ) +); + +export default useAuthStore;