add: zustand fundamentals
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// zustand/userStore.ts
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
|
||||
type User = {
|
||||
id: string
|
||||
name: string
|
||||
number: string
|
||||
token: string
|
||||
}
|
||||
|
||||
type AuthStore = {
|
||||
user: User | null
|
||||
isAuthenticated: boolean
|
||||
login: (userData: User) => void
|
||||
logout: () => void
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthStore>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
login: (userData) =>
|
||||
set(() => ({
|
||||
user: userData,
|
||||
isAuthenticated: true,
|
||||
})),
|
||||
logout: () =>
|
||||
set(() => ({
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
})),
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage', // Key in localStorage
|
||||
}
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user