import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom';
import LoginPage from '../pages/LoginPage';
import HomePage from '../pages/HomePage'; // Crearemos esta página simple
import { useAuth } from '../contexts/AuthContext';
import ChangePasswordPage from '../pages/ChangePasswordPage'; // Crearemos esta
import MainLayout from '../layouts/MainLayout'; // Crearemos este
// Componente para proteger rutas
const ProtectedRoute: React.FC<{ children: JSX.Element }> = ({ children }) => {
const { isAuthenticated, isLoading } = useAuth();
if (isLoading) {
// Muestra algo mientras verifica el token (ej: un spinner)
return
Cargando...
;
}
return isAuthenticated ? children : ;
};
// Componente para rutas públicas (redirige si ya está logueado)
const PublicRoute: React.FC<{ children: JSX.Element }> = ({ children }) => {
const { isAuthenticated, isLoading } = useAuth();
if (isLoading) {
return Cargando...
;
}
return !isAuthenticated ? children : ;
};
const AppRoutes = () => {
return (
{/* Rutas Públicas */}
} />
} /> {/* Asumimos que se accede logueado */}
{/* Rutas Protegidas dentro del Layout Principal */}
{/* Layout que tendrá la navegación principal */}
{/* Aquí irán las rutas de los módulos */}
} /> {/* Página por defecto al loguearse */}
{/* } /> */}
{/* } /> */}
{/* ... otras rutas de módulos ... */}
} /> {/* Redirige rutas no encontradas al home */}
}
/>
);
};
export default AppRoutes;