Initialize a framework-specific client for sign-in, sign-up, and session operations.
Frontend authentication
Better Auth · Function
createAuthClient initializes a Better Auth client for calling an authentication server. Configure its server URL when needed, then use the returned APIs for authentication and extend them with plugins.
createAuthClient builds a client instance for communicating with a Better Auth server. Select the framework-specific import when applicable, optionally configure the server URL or path, and then use the returned API; plugins can extend its capabilities.
createAuthClient(options?)| Name | Type | Description |
|---|---|---|
options | object | Configuration object for the client, including the authentication server URL, optional base path, fetch defaults, session settings, and plugins. |
A Better Auth client instance with default authentication functions and any plugin-provided extensions.
import { createAuthClient } from "better-auth/react";
export const authClient = createAuthClient({
baseURL: "http://localhost:3000",
});
await authClient.signIn.email({
email: "test@user.com",
password: "password1234",
});This creates a React-oriented Better Auth client that targets an authentication server, then uses the generated client API for email sign-in.
Frontend authentication
Separate auth server
Custom routing
Shared request configuration
It creates a Better Auth client instance for interacting with the authentication server. The instance exposes default client functions, and plugins can add more capabilities.
Follow-up: How would you target an authentication endpoint under a custom path? Pass the complete URL containing that path or provide the path through the separate basePath option.
Pass baseURL with the authentication server's URL when the server is not on the same domain as the client. The documentation shows this configured in the options object.
Follow-up: What happens when both applications share a domain? The base URL can be omitted.
Use a framework-specific client import, such as better-auth/react for React, and call createAuthClient with the desired options. The resulting instance is then used for authentication operations.
Follow-up: How can cross-cutting request behavior be configured? Supply default fetch settings through fetchOptions.
authClientsignIn.emailfetchOptionsbasePathsessionOptionsplugins