Skip to main content
Better Auth provides a client library for popular frontend frameworks. All framework clients are built on top of a shared core, so methods and hooks are consistent everywhere.

Installation

Create a client instance

Import createAuthClient from the package matching your framework. Pass the base URL of your auth server — if the client and server share the same domain, you can omit this.
lib/auth-client.ts
If your auth server uses a base path other than /api/auth, pass the full URL including the path (e.g., http://localhost:3000/custom-path/auth), or use the basePath option.

Usage

The client exposes a set of functions by default that can be extended with plugins.
auth-client.ts

Hooks

Framework-specific clients provide reactive hooks. All hooks are available on the root client object and start with use.

useSession

user.tsx

Fetch options

The client uses Better Fetch — a typed fetch wrapper built by the same team. Pass default fetch options when creating the client:
auth-client.ts
You can also pass fetch options per call:

Session options

Configure how the client fetches and revalidates sessions:
auth-client.ts

Disabling default fetch plugins

The client includes a redirect plugin for browser environments. Disable it for non-browser environments (e.g., React Native):
auth-client.ts

Disabling hook rerenders

Some endpoints trigger atom signals that cause hooks like useSession to rerender. Suppress this for calls that should not update the UI:
If you suppress the signal but still want to update the UI, manually refetch:

Error handling

Most client functions return a { data, error } object:
Or pass an onError callback:
Hooks like useSession also expose error and isPending:

Error codes

The client exposes $ERROR_CODES — a typed map of all server error codes. Use it to build localized error messages:
auth-client.ts

Client plugins

Extend the client with plugins to add new methods or modify existing behavior:
auth-client.ts
See the Plugins documentation for how to create your own client plugins.