- Add bulk XML CFDI upload support (up to 300MB) - Add period selector component for month/year navigation - Fix session persistence on page refresh (Zustand hydration) - Fix income/expense classification based on tenant RFC - Fix IVA calculation from XML (correct Impuestos element) - Add error handling to reportes page - Support multiple CORS origins - Update reportes service with proper Decimal/BigInt handling - Add RFC to tenant view store for proper CFDI classification - Update README with changelog and new features Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { create } from 'zustand';
|
|
import { persist } from 'zustand/middleware';
|
|
import type { UserInfo } from '@horux/shared';
|
|
|
|
interface AuthState {
|
|
user: UserInfo | null;
|
|
isAuthenticated: boolean;
|
|
_hasHydrated: boolean;
|
|
setUser: (user: UserInfo | null) => void;
|
|
setTokens: (accessToken: string, refreshToken: string) => void;
|
|
logout: () => void;
|
|
setHasHydrated: (state: boolean) => void;
|
|
}
|
|
|
|
export const useAuthStore = create<AuthState>()(
|
|
persist(
|
|
(set) => ({
|
|
user: null,
|
|
isAuthenticated: false,
|
|
_hasHydrated: false,
|
|
setUser: (user) => set({ user, isAuthenticated: !!user }),
|
|
setTokens: (accessToken, refreshToken) => {
|
|
localStorage.setItem('accessToken', accessToken);
|
|
localStorage.setItem('refreshToken', refreshToken);
|
|
},
|
|
logout: () => {
|
|
localStorage.removeItem('accessToken');
|
|
localStorage.removeItem('refreshToken');
|
|
set({ user: null, isAuthenticated: false });
|
|
},
|
|
setHasHydrated: (state) => set({ _hasHydrated: state }),
|
|
}),
|
|
{
|
|
name: 'horux-auth',
|
|
partialize: (state) => ({ user: state.user, isAuthenticated: state.isAuthenticated }),
|
|
onRehydrateStorage: () => (state) => {
|
|
state?.setHasHydrated(true);
|
|
},
|
|
}
|
|
)
|
|
);
|