Skip to content
Dashboard
Theme
Theme

React SDK

The @ohauthcat/react bindings: a provider, hooks and components for the hosted login, and an embeddable setup portal.

View Markdown

@ohauthcat/react wraps the JavaScript SDK for React 18 and later. Install it next to @ohauthcat/js, which is a peer dependency.

npm install @ohauthcat/react @ohauthcat/js

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.

  • 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.
  • 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 from your backend, with the same options as the JavaScript SDK’s attachPortalEmbed. Turn on portal embedding for the environment first.

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