React SDK
The @ohauthcat/react bindings: a provider, hooks and components for the hosted login, and an embeddable setup portal.
@ohauthcat/react wraps the JavaScript SDK for React 18 and later. Install it next to @ohauthcat/js, which is a peer dependency.
Install
Section titled “Install”npm install @ohauthcat/react @ohauthcat/jsProvider
Section titled “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(, where you route to returnTo.
useAuth()returnsstatus,isSignedIn,user,error(the last callback error),signIn,signOut,switchOrganization,getAccessTokenand theclient.useUser(),useOrganization()anduseAccessToken()return the parts you need.
Components
Section titled “Components”SignedInandSignedOutrender their children only in that state.RequireAuthshows itsfallbackuntil the user is signed in.OrganizationSwitcher(propsorganizationsandlabel) switches between the user’s organizations.AdminPortal(propsurl,title,onCompleteand the rest) embeds a portal link from your backend, with the same options as the JavaScript SDK’sattachPortalEmbed. 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.