import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { useAuth } from './useCan';

/** Gate all protected routes: redirect to /login when not authenticated. */
export default function RequireAuth() {
  const user = useAuth();
  const loc = useLocation();
  if (!user) return <Navigate to="/login" replace state={{ from: loc.pathname }} />;
  return <Outlet />;
}
