# React SDK

`@ohauthcat/react` wraps the [JavaScript SDK](/sdks/javascript/) for React 18 and later. Install it next to `@ohauthcat/js`, which is a peer dependency.

## Install

```sh
npm install @ohauthcat/react @ohauthcat/js
```

## Provider

Create an `OhAuthCatClient` and pass it as the `client` prop of `OhAuthCatProvider`. On the redirect page the provider finishes the sign-in itself (turn this off with `handleRedirectCallback={false}`) and calls `onRedirectCallback({ user, returnTo })`, where you route to `returnTo`.

## Hooks

- `useAuth()` returns `status`, `isSignedIn`, `user`, `error` (the last callback error), `signIn`, `signOut`, `switchOrganization`, `getAccessToken` and the `client`.
- `useUser()`, `useOrganization()` and `useAccessToken()` return the parts you need.

## Components

- `SignedIn` and `SignedOut` render their children only in that state.
- `RequireAuth` shows its `fallback` until the user is signed in.
- `OrganizationSwitcher` (props `organizations` and `label`) switches between the user's organizations.
- `AdminPortal` (props `url`, `title`, `onComplete` and the rest) embeds a [portal link](/hosted-portal/portal-links/) from your backend, with the same options as the JavaScript SDK's `attachPortalEmbed`. Turn on [portal embedding](/hosted-portal/#embed-the-portal-in-your-app) for the environment first.

Components take user-facing text (`label`, `title`, `fallback`) as props, so your app's translations supply it.
