Files
pwa/src/components/ProtectedRoute.tsx
T

26 lines
683 B
TypeScript
Raw Normal View History

2025-11-18 20:22:25 +03:30
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}</>;
}