26 lines
683 B
TypeScript
26 lines
683 B
TypeScript
import { Navigate, useLocation } from 'react-router-dom';
|
|||
|
|
import { useAtom } from 'jotai';
|
||
|
|
import { isAuthenticatedAtom } from '@/atoms/auth';
|
||
|
|
import { isSupabaseConfigured } from '@/services/supabase';
|
||
|
|
|
||
|
|
interface ProtectedRouteProps {
|
||
|
|
children: React.ReactNode;
|
||
|
|
}
|
||
|
|
|
||
|
|
export function ProtectedRoute({ children }: ProtectedRouteProps) {
|
||
|
|
const [isAuthenticated] = useAtom(isAuthenticatedAtom);
|
||
|
|
const location = useLocation();
|
||
|
|
|
||
|
|
// In offline mode, allow access without authentication
|
||
|
|
if (!isSupabaseConfigured) {
|
||
|
|
return <>{children}</>;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (!isAuthenticated) {
|
||
|
|
return <Navigate to="/login" state={{ from: location }} replace />;
|
||
|
|
}
|
||
|
|
|
||
|
|
return <>{children}</>;
|
||
|
|
}
|
||
|
|
|