ibanking-api-ai/lib/auth/client/useAuthStore.ts

61 lines
1.3 KiB
TypeScript

'use client';
import { create } from 'zustand';
export interface User {
id: string;
userName: string;
name: string;
email?: string;
userType: 'master' | 'operador' | 'cliente';
status: 'activo' | 'bloqueado' | 'suspendido' | 'inactivo' | 'reiniciado';
}
export interface AuthStoreState {
user: User | null;
isLoading: boolean;
isAuthenticated: boolean;
requires2FA: boolean;
tempUserName: string | null;
setUser: (user: User | null) => void;
setRequires2FA: (requires: boolean, userName?: string | null) => void;
logout: () => void;
setLoading: (loading: boolean) => void;
}
export const useAuthStore = create<AuthStoreState>((set) => ({
user: null,
isLoading: false,
isAuthenticated: false,
requires2FA: false,
tempUserName: null,
setUser: (user) =>
set({
user,
isAuthenticated: !!user,
requires2FA: false,
tempUserName: null,
isLoading: false,
}),
setRequires2FA: (requires, userName = null) =>
set({
requires2FA: requires,
tempUserName: userName,
isLoading: false,
}),
logout: () =>
set({
user: null,
isAuthenticated: false,
requires2FA: false,
tempUserName: null,
isLoading: false,
}),
setLoading: (loading) => set({ isLoading: loading }),
}));