Spaces:
Sleeping
Sleeping
Download src/components/ProtectedRoute.tsx from Aiprojectttt/DistractIQ: direct link, hf CLI and curl.
- Browser
- Download file 639 Bytes
-
https://huggingface.co/spaces/Aiprojectttt/DistractIQ/resolve/main/src/components/ProtectedRoute.tsx
- Command line
-
hf download hf://spaces/Aiprojectttt/DistractIQ/src/components/ProtectedRoute.tsx
-
curl -L -o ProtectedRoute.tsx https://huggingface.co/spaces/Aiprojectttt/DistractIQ/resolve/main/src/components/ProtectedRoute.tsx
639 Bytes
| import { ReactNode } from "react"; | |
| import { Navigate, useLocation } from "react-router-dom"; | |
| import { useAuth } from "@/contexts/AuthContext"; | |
| export default function ProtectedRoute({ children }: { children: ReactNode }) { | |
| const { user, loading } = useAuth(); | |
| const location = useLocation(); | |
| if (loading) { | |
| return ( | |
| <div className="min-h-screen flex items-center justify-center"> | |
| <div className="h-10 w-10 rounded-full border-2 border-primary/30 border-t-primary animate-spin" /> | |
| </div> | |
| ); | |
| } | |
| if (!user) return <Navigate to="/auth" state={{ from: location }} replace />; | |
| return <>{children}</>; | |
| } | |