add: zustand fundamentals

This commit is contained in:
Mahyar Khanbolooki
2025-06-30 22:53:02 +03:30
parent 09d1093253
commit 5b58b1e6ba
6 changed files with 100 additions and 4 deletions
+39
View File
@@ -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
}
)
)