chore: sync submodule state (parent ref update)
Made-with: Cursor
This commit is contained in:
35
services/token-aggregation/frontend/src/stores/authStore.ts
Normal file
35
services/token-aggregation/frontend/src/stores/authStore.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist, createJSONStorage } from 'zustand/middleware';
|
||||
|
||||
interface AuthState {
|
||||
token: string | null;
|
||||
user: {
|
||||
id: number;
|
||||
username: string;
|
||||
email?: string;
|
||||
role: string;
|
||||
} | null;
|
||||
isAuthenticated: boolean;
|
||||
login: (token: string, user: any) => void;
|
||||
logout: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthState>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
token: null,
|
||||
user: null,
|
||||
isAuthenticated: false,
|
||||
login: (token, user) => {
|
||||
set({ token, user, isAuthenticated: true });
|
||||
},
|
||||
logout: () => {
|
||||
set({ token: null, user: null, isAuthenticated: false });
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'auth-storage',
|
||||
storage: createJSONStorage(() => localStorage),
|
||||
}
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user