Application setup
Create a typed Better Auth server configuration with environment-specific URL and secret values.
Better Auth · Type Alias
BetterAuthOptions describes the configuration object used to create a Better Auth instance. It covers application identity, URLs, databases, authentication features, secrets, and plugins.
BetterAuthOptions is the configuration shape used to describe a Better Auth instance. Define supported settings such as the application name, base URL, secret, database, authentication methods, and plugins, then pass the checked object to betterAuth.
type BetterAuthOptions = { ... }| Name | Type | Description |
|---|---|---|
appName | string | Application display name used by Better Auth. |
baseURL | string | object | Application server URL or dynamic host-resolution configuration. |
database | object | Database configuration for the authentication store. |
plugins | array | Additional Better Auth plugins. |
A Better Auth configuration object accepted by betterAuth.
import { betterAuth } from "better-auth";
import type { BetterAuthOptions } from "better-auth";
const options = {
appName: "My App",
baseURL: process.env.SITE_URL,
secret: process.env.BETTER_AUTH_SECRET,
emailAndPassword: { enabled: true },
} satisfies BetterAuthOptions;
export const auth = betterAuth(options);This validates a Better Auth configuration object against BetterAuthOptions before passing it to betterAuth.
Create a typed Better Auth server configuration with environment-specific URL and secret values.
Configure authentication persistence for a PostgreSQL, MySQL, or SQLite-backed application.
Support preview deployments or multiple production domains with request-dependent base URLs.
Compose built-in and custom authentication behavior through the plugins option.
BetterAuthOptions is the type used to validate the object that configures a Better Auth instance. It can describe settings including appName, baseURL, secret, database, authentication methods, and plugins.
Follow-up: Why use satisfies instead of a broad type assertion? It checks that the object conforms to the options type while preserving useful inference for the object's own properties.
baseURL identifies the root URL where the application server is hosted. It may be a static string or an object that resolves a request-specific URL for multiple allowed hosts.
Follow-up: What must be considered when using the object form? Host matching and request-derived URLs should be constrained with allowed hosts, while forwarded headers require explicit trusted-proxy configuration.
The options can include database configuration and authentication features such as email-and-password sign-in. Plugins are supplied through the plugins option, allowing the instance to extend its behavior.
Follow-up: How would you make a configuration reusable across environments? Keep environment-specific values such as baseURL and secret in environment variables while keeping the shared options structure typed.
appNamebaseURLdatabaseadvanced.trustedProxyHeadersallowedHostspluginsbetterAuth