Download studio/src/components/ProtectedRoute.jsx from shak3008/DiffWeave: direct link, hf CLI and curl.
- Browser
- Download file 550 Bytes
-
https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/ProtectedRoute.jsx
- Command line
-
hf download hf://spaces/shak3008/DiffWeave/studio/src/components/ProtectedRoute.jsx
-
curl -L -o ProtectedRoute.jsx https://huggingface.co/spaces/shak3008/DiffWeave/resolve/main/studio/src/components/ProtectedRoute.jsx
550 Bytes
| import { useAuth } from "../context/AuthContext.jsx"; | |
| import { Navigate, useLocation } from "react-router-dom"; | |
| export default function ProtectedRoute({ children }) { | |
| const { isAuthenticated, token } = useAuth(); | |
| const location = useLocation(); | |
| // Check both React state and localStorage to prevent transition flashes | |
| const hasToken = isAuthenticated || Boolean(token) || Boolean(localStorage.getItem("diffweave_token")); | |
| if (!hasToken) { | |
| return <Navigate to="/login" state={{ from: location }} replace />; | |
| } | |
| return children; | |
| } | |