React SDK
ZauthaProvider
Context provider that manages authentication state for your React app.
The ZauthaProvider component manages authentication state and makes it available to all child components via React context. It must wrap your entire application.
Usage
import { ZauthaProvider } from '@zautha/react';
function App() {
return (
<ZauthaProvider projectKey="pk_live_xxx">
<Router />
</ZauthaProvider>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
projectKey | string | Required | Your project's public API key |
baseUrl | string | "https://auth.zautha.com" | Auth runtime URL (override for self-hosted or development) |
children | ReactNode | Required | Your application |
How It Works
On mount, the provider:
- Checks for an existing session (via cookies)
- If found, fetches the current user from
GET /v1/auth/me - Sets
isLoaded = trueandisSignedInaccordingly - Makes auth state available to
useAuth()anduseUser()hooks
Development Setup
For local development, point the provider to your local auth service:
<ZauthaProvider
projectKey="pk_test_xxx"
baseUrl="http://localhost:5001"
>
{children}
</ZauthaProvider>