zautha
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

PropTypeDefaultDescription
projectKeystringRequiredYour project's public API key
baseUrlstring"https://auth.zautha.com"Auth runtime URL (override for self-hosted or development)
childrenReactNodeRequiredYour application

How It Works

On mount, the provider:

  1. Checks for an existing session (via cookies)
  2. If found, fetches the current user from GET /v1/auth/me
  3. Sets isLoaded = true and isSignedIn accordingly
  4. Makes auth state available to useAuth() and useUser() 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>

On this page