Options
List of all the available options for configuring Better Auth. See Better Auth Options.
appName
The name of the application.
baseURL
Base URL for Better Auth. This is typically the root URL where your application server is hosted.
If not explicitly set, the system will check for the environment variable process.env.BETTER_AUTH_URL
. If not set, it will throw an error.
basePath
Base path for Better Auth. This is typically the path where the Better Auth routes are mounted.
Default: /api/auth
secret
The secret used for encryption, signing, and hashing.
By default, Better Auth will look for the following environment variables:
process.env.BETTER_AUTH_SECRET
process.env.AUTH_SECRET
If none of these environment variables are set, it will default to "better-auth-secret-123456789"
. In production, if it's not set, it will throw an error.
You can generate a good secret using the following command:
database
Database configuration for Better Auth.
Better Auth supports various database configurations including PostgreSQL, MySQL, and SQLite.
Read more about databases here.
secondaryStorage
Secondary storage configuration used to store session and rate limit data.
Read more about secondary storage here.
emailVerification
Email verification configuration.
sendVerificationEmail
: Function to send verification emailsendOnSignUp
: Send verification email automatically after sign up (default:false
)autoSignInAfterVerification
: Auto sign in the user after they verify their emailexpiresIn
: Number of seconds the verification token is valid for (default:3600
seconds)
emailAndPassword
Email and password authentication configuration.
enabled
: Enable email and password authentication (default:false
)disableSignUp
: Disable email and password sign up (default:false
)requireEmailVerification
: Require email verification before a session can be createdminPasswordLength
: Minimum password length (default:8
)maxPasswordLength
: Maximum password length (default:128
)autoSignIn
: Automatically sign in the user after sign upsendResetPassword
: Function to send reset password emailresetPasswordTokenExpiresIn
: Number of seconds the reset password token is valid for (default:3600
seconds)password
: Custom password hashing and verification functions
socialProviders
Configure social login providers.
plugins
List of Better Auth plugins.
user
User configuration options.
modelName
: The model name for the user (default:"user"
)fields
: Map fields to different column namesadditionalFields
: Additional fields for the user tablechangeEmail
: Configuration for changing emaildeleteUser
: Configuration for user deletion
session
Session configuration options.
modelName
: The model name for the session (default:"session"
)fields
: Map fields to different column namesexpiresIn
: Expiration time for the session token in seconds (default:604800
- 7 days)updateAge
: How often the session should be refreshed in seconds (default:86400
- 1 day)additionalFields
: Additional fields for the session tablestoreSessionInDatabase
: Store session in database when secondary storage is provided (default:false
)preserveSessionInDatabase
: Preserve session records in database when deleted from secondary storage (default:false
)cookieCache
: Enable caching session in cookie
account
Account configuration options.
modelName
: The model name for the accountfields
: Map fields to different column namesaccountLinking
: Configuration for account linking
verification
Verification configuration options.
modelName
: The model name for the verification tablefields
: Map fields to different column namesdisableCleanup
: Disable cleaning up expired values when a verification value is fetched
advanced
Advanced configuration options.
ipAddress
: IP address configuration for rate limiting and session trackinguseSecureCookies
: Use secure cookies (default:false
)disableCSRFCheck
: Disable trusted origins check (⚠️ security risk)crossSubDomainCookies
: Configure cookies to be shared across subdomainscookies
: Customize cookie names and attributesdefaultCookieAttributes
: Default attributes for all cookiescookiePrefix
: Prefix for cookiesgenerateId
: Function to generate a unique ID for a model
databaseHooks
Database lifecycle hooks for core operations.
onAPIError
API error handling configuration.
throw
: Throw an error on API error (default:false
)onError
: Custom error handlererrorURL
: URL to redirect to on error (default:/api/auth/error
)
hooks
Request lifecycle hooks.
disabledPaths
Disable specific auth paths.