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;