Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Function

createAuthClient

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.

How it works

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.

Syntax

createAuthClient(options?)

Parameters

NameTypeDescription
optionsobjectConfiguration object for the client, including the authentication server URL, optional base path, fetch defaults, session settings, and plugins.

Returns

A Better Auth client instance with default authentication functions and any plugin-provided extensions.

Key points

  • Use the client entry point matching the frontend framework.
  • Initialization consists of invoking createAuthClient and optionally passing configuration.
  • baseURL identifies the Better Auth server used by the client.
  • The returned client includes built-in operations and supports plugin-based extension.
  • Custom server paths can be represented directly in the configured URL.

Common mistakes

  • For a non-default authentication path, include that path in the URL or configure basePath separately.
  • Use fetchOptions when every request needs shared fetch configuration.

Example: Create a Better Auth client

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.

When to use it

Initialize a framework-specific client for sign-in, sign-up, and session operations.

Frontend authentication

Point the client at an authentication backend hosted on another domain.

Separate auth server

Connect to an auth server whose endpoint uses a non-default base path.

Custom routing

Apply default fetch behavior to requests made through the client.

Shared request configuration

Interview questions

QWhat does createAuthClient return?

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.

QWhen should baseURL be configured?

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.

QHow do you initialize the client in a framework application?

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.

  • authClient
  • signIn.email
  • fetchOptions
  • basePath
  • sessionOptions
  • plugins

Source: Client | Better Auth. Checked 2026-10-15.