import { create } from 'zustand'; import { devtools } from 'zustand/middleware'; export interface ProfileType { id: string; sub: string; iat: number; exp: number; } /** * Auth State Type */ export interface AuthStateType { loggedIn: boolean; email: string | null; profile: ProfileType | null; } /** * Auth Action Type */ export interface AuthActionType { setSignIn: (by: ProfileType) => void; setEmail: (by: string) => void; setSignOut: () => void; } export type AuthStoreType = AuthStateType & AuthActionType; export const useAuthStore = create()( devtools( (set): AuthStoreType => ({ loggedIn: false, email: null, profile: null, setSignIn: (by: ProfileType) => set(() => ({ profile: { ...by }, loggedIn: true, })), setEmail: (by: string) => set(() => ({ email: by })), setSignOut: () => set(() => ({ loggedIn: false, email: null, })), }), { name: 'auth' }, ), );