Improve ProtectedRoute

This commit is contained in:
Arthur Belleville 2025-03-27 08:59:34 +01:00
parent ba1f48ad0d
commit 2e429535ab
No known key found for this signature in database
2 changed files with 4 additions and 3 deletions

View file

@ -26,7 +26,7 @@ export const App = () => {
<Route
path="/"
element={
<ProtectedRoute>
<ProtectedRoute to="/landing">
<TabloPage />
</ProtectedRoute>
}

View file

@ -3,12 +3,13 @@ import { useSession } from "../contexts/SessionContext";
import { Navigate } from "react-router-dom";
interface ProtectedRouteProps {
children: ReactNode;
to?: string;
}
export const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
export const ProtectedRoute = ({ children, to }: ProtectedRouteProps) => {
const { session } = useSession();
if (!session) {
return <Navigate to="/login" replace />;
return <Navigate to={to ?? "/login"} replace />;
}
// If authenticated, render the protected component