import { useState } from 'react'; import { Routes, Route, Navigate, useNavigate } from 'react-router-dom'; import { pb } from '@/services/pocketbase'; // Layout & Pages import Login from '@/pages/Login'; import DashboardLayout from '@/layouts/DashboardLayout'; import TrustCenter from '@/pages/TrustCenter'; import ServiceDesk from '@/pages/ServiceDesk'; import DocumentVault from '@/pages/DocumentVault'; import AccountSettings from '@/pages/AccountSettings'; import { InfrastructureEvolution } from '@/pages/trustcenter/InfrastructureEvolution'; import Analytics from '@/pages/trustcenter/Analytics'; import Backups from '@/pages/trustcenter/Backups'; import NewTicket from '@/pages/servicedesk/NewTicket'; import TicketDetail from '@/pages/servicedesk/TicketDetail'; import UpdatePasswordPage from './pages/accountsettings/UpdatePasswordPage'; function App() { const [isAuthenticated, setIsAuthenticated] = useState(pb.authStore.isValid); const navigate = useNavigate(); const handleLogout = () => { pb.authStore.clear(); setIsAuthenticated(false); navigate('/', { replace: true }); }; // --- SAS DE SÉCURITÉ (Auth Guard) --- // Si non authentifié, on force l'affichage du composant Login peu importe l'URL demandée. if (!isAuthenticated) { return ( { setIsAuthenticated(true); navigate('/dashboard', { replace: true }); }} /> } /> ); } // --- APPLICATION SÉCURISÉE --- // Une fois connecté, le DashboardLayout enveloppe nos véritables routes (URLs) return ( {/* Redirection par défaut */} } /> {/* Pages du menu principal */} } /> } /> } /> } /> {/* Pages stratégiques (anciennes modales) */} } /> } /> } /> } /> } /> } /> {/* Sécurité : Si l'URL n'existe pas, on redirige vers le dashboard */} } /> ); } export default App;