> For the complete documentation index, see [llms.txt](https://docs.humanity.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.humanity.org/build-with-humanity/build-with-the-sdk-api/humanity-org-react-sdk.md).

# @humanity-org/react-sdk

React-first setup, core components and hooks, authentication flow, and essential usage patterns for the Humanity React SDK.

{% hint style="info" %}
Not building in React, or need full OAuth control? → [@humanity-org/connect-sdk](https://docs.humanity.org/build-with-humanity/build-with-the-sdk-api/humanity-org-connect-sdk.md)
{% endhint %}

The `@humanity-org/react-sdk` is the official React integration for Humanity. It provides pre-built components and hooks for OAuth authentication and credential verification **with full Typescript typings** — reducing integration time from days to \~30 minutes.

{% hint style="warning" %}
ℹ️ **Node requirement:** Node 18 or higher.
{% endhint %}

## Installation

```bash
npm install @humanity-org/react-sdk
# or
yarn add @humanity-org/react-sdk
# or
pnpm add @humanity-org/react-sdk
```

**Peer dependencies** (install if not already present):

```bash
npm install react react-dom
```

***

## Prerequisites

Before integrating, you need a **Humanity client ID**. Register your application in the [Humanity Developer Portal](https://developers.humanity.org/) and note your:

* `clientId` — e.g. `hp_xxx`
* `redirectUri` — the OAuth callback URL you registered (e.g. `https://yourapp.com/callback`)

***

## Getting started

#### Step 1 — Wrap your app with `HumanityProvider`

Place `HumanityProvider` at the root of your application. All SDK components and hooks must be rendered inside it.

```tsx
import { HumanityProvider } from '@humanity-org/react-sdk';

function App() {
  return (
    <HumanityProvider
      clientId={process.env.HUMANITY_CLIENT_ID!}
      redirectUri={process.env.HUMANITY_REDIRECT_URI!}
    >
      {/* rest of your app */}
    </HumanityProvider>
  );
}
```

#### Step 2 — Add a login button

```tsx
import { HumanityConnect } from '@humanity-org/react-sdk';

function LoginPage() {
  return (
    <HumanityConnect
      scopes={['openid', 'profile.full', 'identity:read']}
      onSuccess={(result) => console.log('Logged in!', result)}
    />
  );
}
```

#### Step 3 — Gate content on verification

```tsx
import { useAuth, HumanityGate } from '@humanity-org/react-sdk';

function Dashboard() {
  const { user, isAuthenticated, logout } = useAuth();

  if (!isAuthenticated) return <p>Please log in</p>;

  return (
    <HumanityGate
      preset="is_21_plus"
      fallback={<p>Age verification required</p>}
    >
      <h1>Welcome, {user?.name}!</h1>
      <button onClick={logout}>Sign Out</button>
    </HumanityGate>
  );
}

```

***

## Sandbox vs Production

Use `environment="sandbox"` during development to test without real credentials:

```tsx
<HumanityProvider
  clientId="app_xxx"
  redirectUri="http://localhost:3000/callback"
  environment="sandbox"
>
  <App />
</HumanityProvider>
```

{% hint style="warning" %}
⚠️ **Warning:** Register separate redirect URIs for sandbox and production in the [Developer Portal](https://developers.humanity.org).
{% endhint %}

***

## Token Storage

The `storage` prop controls where OAuth tokens are kept:

| Value            | Security | Persists on refresh |
| ---------------- | -------- | ------------------- |
| `memory`         | Highest  | No                  |
| `sessionStorage` | Medium   | No                  |
| `localStorage`   | Lower    | Yes                 |

`memory` is the default and recommended for most apps. Use `localStorage` only if you require persistence and understand the XSS risk (Cross-site Scripting).

***

{% hint style="success" %}
Need integration examples?. Head to [react-sdk-examples](https://docs.humanity.org/starter-templates-and-examples/sdk-integration-templates/react-sdk-examples.md)
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.humanity.org/build-with-humanity/build-with-the-sdk-api/humanity-org-react-sdk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
