Spaces:
Sleeping
Sleeping
File size: 1,027 Bytes
e9d1895 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import { Loader2 } from "lucide-react";
import { useAuth } from "../context/AuthContext";
import { Navigate, useLocation } from "react-router-dom";
export default function ProtectedRoute({ children }) {
const { authenticated, loading } = useAuth();
const location = useLocation();
if (loading) {
return (
<div className="min-h-screen flex items-center justify-center bg-white dark:bg-[#0a0a0f] transition-colors duration-300">
<div className="relative z-10 flex flex-col items-center gap-4">
<div className="relative">
<div className="absolute inset-0 bg-indigo-500 rounded-full blur-xl opacity-20 animate-pulse" />
<Loader2 className="relative w-10 h-10 text-indigo-500 dark:text-indigo-400 animate-spin" />
</div>
<p className="text-sm text-[var(--c-text-secondary)]">Loading...</p>
</div>
</div>
);
}
if (!authenticated) {
return <Navigate to="/login" state={{ from: location }} replace />;
}
return children;
}
|