initial
This commit is contained in:
24
frontend/src/store/auth.ts
Normal file
24
frontend/src/store/auth.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { create } from "zustand";
|
||||
import { persist } from "zustand/middleware";
|
||||
import type { User } from "@/types";
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
user: User | null;
|
||||
setAuth: (token: string, user: User) => void;
|
||||
logout: () => void;
|
||||
isAdmin: () => boolean;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
token: null,
|
||||
user: null,
|
||||
setAuth: (token, user) => set({ token, user }),
|
||||
logout: () => set({ token: null, user: null }),
|
||||
isAdmin: () => !!get().user?.is_admin,
|
||||
}),
|
||||
{ name: "ai-rpg-auth" }
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user