Integrate AuthInitializer component to restore authentication state on app load and enhance User type to align with OpenAPI spec.

This commit is contained in:
2025-11-02 05:59:00 +01:00
parent 29ff97f726
commit 4885df80a7
4 changed files with 55 additions and 3 deletions

View File

@@ -0,0 +1,41 @@
/**
* AuthInitializer Component
* Loads authentication state from storage on app initialization
* Must be a client component within the Providers tree
*/
'use client';
import { useEffect } from 'react';
import { useAuthStore } from '@/stores/authStore';
/**
* AuthInitializer - Initializes auth state from encrypted storage on mount
*
* This component should be included in the app's Providers to ensure
* authentication state is restored from storage when the app loads.
*
* @example
* ```tsx
* // In app/providers.tsx
* export function Providers({ children }) {
* return (
* <QueryClientProvider>
* <AuthInitializer />
* {children}
* </QueryClientProvider>
* );
* }
* ```
*/
export function AuthInitializer() {
const loadAuthFromStorage = useAuthStore((state) => state.loadAuthFromStorage);
useEffect(() => {
// Load auth state from encrypted storage on mount
loadAuthFromStorage();
}, [loadAuthFromStorage]);
// This component doesn't render anything
return null;
}

View File

@@ -1,5 +1,8 @@
// Authentication components
// Initialization
export { AuthInitializer } from './AuthInitializer';
// Route protection
export { AuthGuard } from './AuthGuard';