betterAuth(). For the full TypeScript source, see packages/better-auth/src/types/options.ts.
Quick example
auth.ts
Top-level options
The human-readable name of your application. Used in emails and the default
error page.
Root URL where your application server is hosted. If a path component is
included it takes precedence over
basePath.Falls back to the BETTER_AUTH_URL environment variable, then to request
inference. Always set this explicitly in production.The path prefix where Better Auth routes are mounted. Overridden when
baseURL includes a path.Secret used for encryption, signing, and hashing. In production Better Auth
throws if this is not set.Reads from
BETTER_AUTH_SECRET or AUTH_SECRET environment variables when
not provided explicitly.Versioned secrets for non-destructive secret rotation. The first entry is the
active key for all new encryption; remaining entries are decryption-only.Can also be set via the When
BETTER_AUTH_SECRETS environment variable:.env
secrets is configured, the singular secret is only used as a fallback
for decrypting legacy data. Both can coexist during migration.Origins allowed to make cross-origin requests. Accepts a static array,
wildcard patterns, or an async function for dynamic resolution.Static:Wildcard patterns:
Dynamic:
| Pattern | Description |
|---|---|
? | Matches exactly one character (not /) |
* | Matches zero or more characters that don’t cross / |
** | Matches zero or more characters including / |
The
request parameter is undefined during initialization and when
calling auth.api directly. Always return default origins for the
undefined case.List of Better Auth plugins to load.
Auth paths that should return 404. Useful for disabling sign-up in
closed-beta or invite-only apps.
Controls anonymous usage telemetry sent to the Better Auth team.
database
Primary database configuration. Supports PostgreSQL, MySQL, and SQLite via
the built-in Kysely adapter, or any ORM adapter (Prisma, Drizzle, MongoDB).Read the database docs for adapter-specific setup.
Optional fast key-value storage (Redis, Cloudflare KV, etc.) for sessions,
verification tokens, and rate-limit counters.
emailAndPassword
Enable email and password authentication.
Prevent new accounts from being created via email/password.
Block session creation until the user verifies their email.
Minimum accepted password length.
Maximum accepted password length.
Automatically create a session after a successful sign-up.
Function called to deliver the password-reset email.
Seconds until a reset-password token expires.
Revoke all other sessions when a user resets their password.
Override the default
scrypt password hashing with a custom implementation.emailVerification
Function called to send verification emails.
Send a verification email automatically after sign-up. When
undefined,
follows the requireEmailVerification setting.Automatically sign the user in after they verify their email.
Seconds until a verification token expires.
socialProviders
Configure one or more OAuth / OIDC providers. Each key is a provider slug.
OAuth client ID issued by the provider.
OAuth client secret issued by the provider.
Custom callback URL. Defaults to
{baseURL}/api/auth/callback/{provider}.Additional OAuth scopes to request beyond the provider defaults.
Transform the raw provider profile into Better Auth user fields.
Prevent new accounts from being created through this provider.
session
Database table/model name for sessions.
Session lifetime in seconds (default: 7 days).
Extend the session expiry when the session age exceeds this threshold
(seconds). Set to
0 to refresh on every request.Disable automatic expiry extension regardless of
updateAge.Extra fields to store on the session record.
Persist sessions in the primary database even when
secondaryStorage is
configured.Cache session data in a short-lived signed cookie to avoid a database
round-trip on every request.
user
Database table/model name for users.
Map built-in field names to different database column names.
Extra fields added to the user table. Set
input: false for fields that
should not be settable by the client (e.g. role).Configuration for the change-email flow.
enabled— allow authenticated users to change their emailsendChangeEmailConfirmation— function to deliver confirmation link
Configuration for account deletion.
enabled— allow users to delete their own accountsendDeleteAccountVerification— function to deliver confirmation linkbeforeDelete/afterDelete— lifecycle callbacks
account
Encrypt access/refresh tokens before writing them to the database.
Allow users to link multiple OAuth providers to one account.
Providers whose verified email is trusted for automatic account linking.
rateLimit
Defaults to
true in production, false in development.Time window in seconds.
Maximum requests per window across all routes.
Per-path overrides.
Where to persist rate-limit counters.
advanced
Force the
Secure flag on cookies regardless of protocol. Automatically
true when baseURL uses https.Disable all CSRF protection including origin header validation and Fetch
Metadata checks.
Disable URL validation for
callbackURL, redirectTo, and other redirect
targets. Also disables CSRF protection for backward compatibility.Share session cookies across subdomains.
Custom prefix for all cookie names.
Trusted headers to read the client IP from.
Override the default nanoid-based ID generation.
false— let the database generate IDs"serial"— use auto-increment"uuid"— use random UUID- function — custom generator
(opts: { model, size? }) => string
Defer non-critical work to run after the response is sent. Pass
waitUntil from your serverless platform.Treat routes with and without a trailing slash as equivalent.
logger
Minimum log level to output.
Suppress all log output.
Replace the built-in logger with a custom implementation.
databaseHooks
Run code before or after core database operations. The before hook can
return modified data; the after hook is fire-and-forget.
hooks
Request-level middleware that runs before or after every matched request.
onAPIError
Re-throw API errors instead of returning an error response.
Custom error handler invoked on every API error.
Redirect target for errors that occur in browser flows.
Customize colors, sizes, and fonts of the built-in error page at
/api/auth/error.verification
Skip deleting expired verification records on read.
How to store verification identifiers (OTP keys, magic-link tokens, etc.).
Write verification records to the primary database even when
secondaryStorage is configured.