DistractIQ / src /components /ProtectedRoute.tsx
github-actions
Initial clean deploy
7ff860b
Raw
History Blame Contribute Delete
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}</>;
}