first commit
This commit is contained in:
35
src/app/store/authStore.ts
Normal file
35
src/app/store/authStore.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { create } from 'zustand'
|
||||
import { persist } from 'zustand/middleware'
|
||||
|
||||
export interface AuthUser {
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
role: 'admin' | 'manager' | 'viewer'
|
||||
avatar?: string
|
||||
}
|
||||
|
||||
interface AuthState {
|
||||
token: string | null
|
||||
user: AuthUser | null
|
||||
isAuthenticated: boolean
|
||||
setAuth: (token: string, user: AuthUser) => void
|
||||
clearAuth: () => void
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
token: null,
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
setAuth: (token, user) =>
|
||||
set({ token, user, isAuthenticated: true }),
|
||||
clearAuth: () =>
|
||||
set({ token: null, user: null, isAuthenticated: false }),
|
||||
}),
|
||||
{
|
||||
name: 'tbbank-auth',
|
||||
},
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user