forked from
slices.network/slices
Highly ambitious ATProtocol AppView service and sdks
1import { Navigate, useLocation } from "react-router-dom";
2import { useSessionContext } from "../lib/useSession.ts";
3import LoadingFallback from "../LoadingFallback.tsx";
4
5interface ProtectedRouteProps {
6 children: React.ReactNode;
7}
8
9/**
10 * Protected route wrapper - redirects to /login if not authenticated
11 */
12export function ProtectedRoute({ children }: ProtectedRouteProps) {
13 const { session, isLoading } = useSessionContext();
14 const location = useLocation();
15
16 if (isLoading) {
17 return <LoadingFallback />;
18 }
19
20 if (!session?.authenticated) {
21 return <Navigate to="/login" state={{ from: location }} replace />;
22 }
23
24 return <>{children}</>;
25}