Initial commit: Velocity-OS migration
This commit is contained in:
45
webos/src/store/authStore.ts
Normal file
45
webos/src/store/authStore.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { create } from 'zustand';
|
||||
import { devtools, persist } from 'zustand/middleware';
|
||||
|
||||
/**
|
||||
* authStore — JWT session + user profile
|
||||
*/
|
||||
interface User {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
role: 'SALES_BROKER' | 'SALES_DIRECTOR' | 'ADMIN';
|
||||
avatarUrl?: string;
|
||||
}
|
||||
|
||||
interface AuthStore {
|
||||
user: User | null;
|
||||
token: string | null;
|
||||
isAuthenticated: boolean;
|
||||
// Actions
|
||||
setSession: (user: User, token: string) => void;
|
||||
clearSession: () => void;
|
||||
}
|
||||
|
||||
export const useAuthStore = create<AuthStore>()(
|
||||
devtools(
|
||||
persist(
|
||||
(set) => ({
|
||||
user: null,
|
||||
token: null,
|
||||
isAuthenticated: false,
|
||||
|
||||
setSession: (user, token) =>
|
||||
set({ user, token, isAuthenticated: true }, false, 'auth/setSession'),
|
||||
|
||||
clearSession: () =>
|
||||
set({ user: null, token: null, isAuthenticated: false }, false, 'auth/clearSession'),
|
||||
}),
|
||||
{
|
||||
name: 'velocity-auth',
|
||||
partialize: (state) => ({ token: state.token, user: state.user }),
|
||||
}
|
||||
),
|
||||
{ name: 'AuthStore' }
|
||||
)
|
||||
);
|
||||
Reference in New Issue
Block a user