Integrate AuthInitializer component to restore authentication state on app load and enhance User type to align with OpenAPI spec.
This commit is contained in:
41
frontend/src/components/auth/AuthInitializer.tsx
Normal file
41
frontend/src/components/auth/AuthInitializer.tsx
Normal 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;
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
// Authentication components
|
||||
|
||||
// Initialization
|
||||
export { AuthInitializer } from './AuthInitializer';
|
||||
|
||||
// Route protection
|
||||
export { AuthGuard } from './AuthGuard';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user