Some checks failed
Velocity-OS Deployment Pipeline / lint (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / build-and-push (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (agents) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (core) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (media-engine) (push) Has been cancelled
Velocity-OS Deployment Pipeline / sign-images (webos) (push) Has been cancelled
Velocity-OS Deployment Pipeline / notify-ingress (push) Has been cancelled
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
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' | 'SUPERADMIN' | string;
|
|
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,
|
|
isAuthenticated: Boolean(state.token && state.user),
|
|
}),
|
|
}
|
|
),
|
|
{ name: 'AuthStore' }
|
|
)
|
|
);
|