React SDK
Hooks and headless components for React single-page applications.
@wocha/react provides React hooks and headless components for Wocha authentication in single-page applications. It implements OAuth 2.0 authorisation code with PKCE as a public client.
Installation
pnpm add @wocha/reactnpx @wocha/cli init --framework react-spaQuick start
Register your redirect URI in the Console before testing.
Hooks
All hooks must be used inside WochaProvider.
useSession()
useOrg()
Switch organisation context when the user belongs to multiple orgs:
useProductOrgs(productSlug)
Filter organisations to only those linked to a specific product:
Calls GET /api/v1/account/organisations?product=<slug> and returns
only organisations where the product has been provisioned. Falls back
to the full org_ids list if the call fails or the product has no
linked organisations.
usePermissions()
Check SpiceDB permissions client-side when apiUrl is configured:
Components
Headless components are available for common UI patterns:
For pre-built UI, see @wocha/ui.
Learn more
- React quickstart
- Next.js SDK — for App Router with server-side sessions