Installation
Create a client instance
ImportcreateAuthClient 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.
- React
- Vue
- Svelte
- Solid
- Vanilla
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 withuse.
useSession
- React
- Vue
- Svelte
- Solid
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
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 likeuseSession to rerender. Suppress this for calls that should not update the UI:
Error handling
Most client functions return a{ data, error } object:
onError callback:
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