<UrProvider> is the heart of the React SDK. It initializes the urBackend client, manages global authentication state, and synchronizes the user’s session seamlessly across your application.
You must wrap your entire application (or at least the parts that require authentication and database access) inside this provider.
Usage
Props
| Prop | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your project’s Publishable API Key (pk_live_...). |
baseUrl | string | No | Overrides the default urBackend API URL. Useful for self-hosted instances. |
children | React.ReactNode | Yes | The components to render inside the provider. |
How it works
When<UrProvider> mounts, it automatically:
- Initializes a singleton
@urbackend/sdkinstance. - Checks
localStorageand cookies for an existing active session. - Automatically attempts to refresh the session in the background if the access token has expired.
- Exposes the
AuthUserstate and SDK client to all child components via React Context (accessed through hooks likeuseUseranduseDb).
The provider sets up global state. You only ever need one
<UrProvider> at the root of your React tree.