Spaces:
Running
Running
Download src/components/Shared/ProtectedRoute.jsx from STAR-GROUP/model-test-react: direct link, hf CLI and curl.
- Browser
- Download file 496 Bytes
-
https://huggingface.co/spaces/STAR-GROUP/model-test-react/resolve/main/src/components/Shared/ProtectedRoute.jsx
- Command line
-
hf download hf://spaces/STAR-GROUP/model-test-react/src/components/Shared/ProtectedRoute.jsx
-
curl -L -o ProtectedRoute.jsx https://huggingface.co/spaces/STAR-GROUP/model-test-react/resolve/main/src/components/Shared/ProtectedRoute.jsx
496 Bytes
| import React from "react"; | |
| import { Navigate } from "react-router-dom"; | |
| import { useAuth } from "../../context/AuthContext"; | |
| const ProtectedRoute = ({ children }) => { | |
| const { authenticated, loading } = useAuth(); | |
| if (loading) { | |
| return <div>Loading...</div>; // ✅ Wait until token check completes | |
| } | |
| if (!authenticated) { | |
| return <Navigate to="/login" state={{ from: window.location.pathname }} />; | |
| } | |
| return children; | |
| }; | |
| export default ProtectedRoute; | |