Skip to main content
This page documents every option accepted by betterAuth(). For the full TypeScript source, see packages/better-auth/src/types/options.ts.

Quick example

auth.ts

Top-level options

string
The human-readable name of your application. Used in emails and the default error page.
string
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.
Relying on request inference is not recommended. For security and stability, always set baseURL explicitly or via the BETTER_AUTH_URL environment variable.
string
default:"/api/auth"
The path prefix where Better Auth routes are mounted. Overridden when baseURL includes a path.
string
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.
Array<{ version: number; value: string }>
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 BETTER_AUTH_SECRETS environment variable:
.env
When secrets is configured, the singular secret is only used as a fallback for decrypting legacy data. Both can coexist during migration.
string[] | ((request?: Request) => string[] | Promise<string[]>)
Origins allowed to make cross-origin requests. Accepts a static array, wildcard patterns, or an async function for dynamic resolution.Static:
Wildcard patterns:
Dynamic:
The request parameter is undefined during initialization and when calling auth.api directly. Always return default origins for the undefined case.
BetterAuthPlugin[]
List of Better Auth plugins to load.
string[]
Auth paths that should return 404. Useful for disabling sign-up in closed-beta or invite-only apps.
{ enabled: boolean }
default:"{ enabled: false }"
Controls anonymous usage telemetry sent to the Better Auth team.

database

DatabaseConfiguration
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.
SecondaryStorageConfig
Optional fast key-value storage (Redis, Cloudflare KV, etc.) for sessions, verification tokens, and rate-limit counters.

emailAndPassword

boolean
default:"false"
Enable email and password authentication.
boolean
default:"false"
Prevent new accounts from being created via email/password.
boolean
Block session creation until the user verifies their email.
number
default:"8"
Minimum accepted password length.
number
default:"128"
Maximum accepted password length.
boolean
default:"true"
Automatically create a session after a successful sign-up.
(opts: { user, url, token }) => Promise<void>
Function called to deliver the password-reset email.
number
default:"3600"
Seconds until a reset-password token expires.
boolean
default:"false"
Revoke all other sessions when a user resets their password.
{ hash, verify }
Override the default scrypt password hashing with a custom implementation.

emailVerification

(opts: { user, url, token }) => Promise<void>
Function called to send verification emails.
boolean
Send a verification email automatically after sign-up. When undefined, follows the requireEmailVerification setting.
boolean
Automatically sign the user in after they verify their email.
number
default:"3600"
Seconds until a verification token expires.

socialProviders

Configure one or more OAuth / OIDC providers. Each key is a provider slug.
string
required
OAuth client ID issued by the provider.
string
required
OAuth client secret issued by the provider.
string
Custom callback URL. Defaults to {baseURL}/api/auth/callback/{provider}.
string[]
Additional OAuth scopes to request beyond the provider defaults.
(profile) => Partial<User>
Transform the raw provider profile into Better Auth user fields.
boolean
Prevent new accounts from being created through this provider.

session

string
default:"session"
Database table/model name for sessions.
number
default:"604800"
Session lifetime in seconds (default: 7 days).
number
default:"86400"
Extend the session expiry when the session age exceeds this threshold (seconds). Set to 0 to refresh on every request.
boolean
default:"false"
Disable automatic expiry extension regardless of updateAge.
Record<string, FieldConfig>
Extra fields to store on the session record.
boolean
default:"false"
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

string
default:"user"
Database table/model name for users.
Record<string, string>
Map built-in field names to different database column names.
Record<string, FieldConfig>
Extra fields added to the user table. Set input: false for fields that should not be settable by the client (e.g. role).
ChangeEmailConfig
Configuration for the change-email flow.
  • enabled — allow authenticated users to change their email
  • sendChangeEmailConfirmation — function to deliver confirmation link
DeleteUserConfig
Configuration for account deletion.
  • enabled — allow users to delete their own account
  • sendDeleteAccountVerification — function to deliver confirmation link
  • beforeDelete / afterDelete — lifecycle callbacks

account

boolean
default:"false"
Encrypt access/refresh tokens before writing them to the database.
boolean
default:"true"
Allow users to link multiple OAuth providers to one account.
string[] | ((request?) => string[])
Providers whose verified email is trusted for automatic account linking.

rateLimit

boolean
Defaults to true in production, false in development.
number
default:"10"
Time window in seconds.
number
default:"100"
Maximum requests per window across all routes.
Record<string, { window: number; max: number }>
Per-path overrides.
'memory' | 'database' | 'secondary-storage'
default:"memory"
Where to persist rate-limit counters.

advanced

boolean
default:"false"
Force the Secure flag on cookies regardless of protocol. Automatically true when baseURL uses https.
boolean
default:"false"
Disable all CSRF protection including origin header validation and Fetch Metadata checks.
Disabling CSRF checks exposes your application to CSRF attacks.
boolean
default:"false"
Disable URL validation for callbackURL, redirectTo, and other redirect targets. Also disables CSRF protection for backward compatibility.
Disabling origin checks opens your app to open-redirect attacks.
{ enabled: boolean; domain: string; additionalCookies?: string[] }
Share session cookies across subdomains.
Custom prefix for all cookie names.
string[]
Trusted headers to read the client IP from.
function | false | 'serial' | 'uuid'
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
(promise: Promise<unknown>) => void
Defer non-critical work to run after the response is sent. Pass waitUntil from your serverless platform.
Enabling background tasks introduces eventual consistency — the response may return optimistic data before the database is updated.
boolean
default:"false"
Treat routes with and without a trailing slash as equivalent.

logger

'debug' | 'info' | 'warn' | 'error'
default:"warn"
Minimum log level to output.
boolean
default:"false"
Suppress all log output.
(level, message, ...args) => void
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.
See the hooks documentation for full details.

onAPIError

boolean
default:"false"
Re-throw API errors instead of returning an error response.
(error, ctx) => void
Custom error handler invoked on every API error.
string
default:"/api/auth/error"
Redirect target for errors that occur in browser flows.
ErrorPageTheme
Customize colors, sizes, and fonts of the built-in error page at /api/auth/error.

verification

boolean
default:"false"
Skip deleting expired verification records on read.
'plain' | 'hashed' | CustomHasher
How to store verification identifiers (OTP keys, magic-link tokens, etc.).
boolean
default:"false"
Write verification records to the primary database even when secondaryStorage is configured.