duckil_plm/fems-app/src/stores/auth.ts

30 lines
580 B
TypeScript
Raw Normal View History

2024-11-02 07:15:56 +09:00
// src/stores/auth.ts
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
interface User {
id: string
name: string
role: string
}
interface AuthState {
user: User | null
token: string | null
setAuth: (user: User, token: string) => void
clearAuth: () => void
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
setAuth: (user, token) => set({ user, token }),
clearAuth: () => set({ user: null, token: null }),
}),
{
name: 'auth-storage',
}
)
)