This feature is currently in alpha, and the design of it is rapidly evolving. Contact us at contact@humanlayer.dev to get early access.

Overview

The React embed channel allows you to embed HumanLayer approval flows directly in your React applications. This enables:

  • Custom approval UIs that match your application’s design
  • In-app approval workflows
  • Real-time updates using websockets
  • Integration with your existing authentication system

Installation

Backend Setup

In general you will need to implement two routes:

  1. Auth - Generate a JWT token containing user/tenant info, usually /api/humanlayer-auth
  2. Embed - Handle the embed requests, usually /api/humanlayer-embed

The specific location of your backend routes can be configured in the HumanLayerProvider component in Frontend Setup.

For HumanLayer to verify the JWT token, you need to use the same signing key that you configured in the HumanLayer dashboard.

Frontend Setup

npm install @humanlayer/react

Components

import { HumanLayerProvider, ApprovalQueue } from "@humanlayer/react";

function App() {
  const [token, setToken] = useState<string>();

  useEffect(() => {
    // Fetch auth token from your backend
    fetch("/api/humanlayer-auth")
      .then((r) => r.json())
      .then((data) => setToken(data.token));
  }, []);

  if (!token) return null;

  return (
    <HumanLayerProvider token={token}>
      <ApprovalQueue />
    </HumanLayerProvider>
  );
}

React Hooks

The React embed package also provides hooks for fetching data:

import { useApprovals } from "@humanlayer/react";

function ApprovalList() {
  const { approvals, loading } = useApprovals();

  if (loading) return <div>Loading...</div>;

  return (
    <div>
      {approvals.map((approval) => (
        <div key={approval.id}>{approval.message}</div>
      ))}
    </div>
  );
}

Next Steps