Better Auth in Rust

Configuration Options

Reference for the public configuration structs exposed by AuthConfig.

This page documents the public configuration types in crates/core/src/config.rs.

AuthConfig

FieldTypeDefaultDescription
secretStringempty until setSigning/encryption secret; must be at least 32 characters
app_nameString"Better Auth"App name used by emails and cookie-related metadata
base_urlString"http://localhost:3000"Base URL for the auth service
base_pathString"/api/auth"Auth route mount prefix
trusted_originsVec<String>[]Origins trusted for CSRF/origin checks
disabled_pathsVec<String>[]Routes that should behave as disabled
sessionSessionConfigsee belowSession token and cookie behavior
jwtJwtConfigsee belowOptional JWT behavior
passwordPasswordConfigsee belowPassword policy and Argon2 settings
accountAccountConfigsee belowOAuth/account-linking behavior
email_providerOption<Arc<dyn EmailProvider>>NoneGlobal email provider
advancedAdvancedConfigsee belowAdvanced cookie, IP, and DB options

SessionConfig

FieldTypeDefaultDescription
expires_inchrono::Duration7 daysSession lifetime
update_ageOption<chrono::Duration>Some(1 day)Age threshold before refreshing a session
disable_session_refreshboolfalseDisable automatic refresh entirely
fresh_ageOption<chrono::Duration>NoneOptional freshness window for sensitive actions
cookie_nameString"better-auth.session_token"Cookie name used for session transport
cookie_secureboolDerived from base_urltrue for HTTPS URLs, false for HTTP URLs
cookie_http_onlybooltruePrevent JavaScript access to the cookie
cookie_same_siteSameSiteLaxSameSite policy
cookie_cacheOption<CookieCacheConfig>NoneOptional cookie-backed session cache

Refresh semantics:

  • update_age = Some(duration): refresh only when older than duration.
  • update_age = None: refresh on every access.
  • disable_session_refresh = true: never refresh automatically.

CookieCacheConfig

FieldTypeDefaultDescription
enabledboolfalseWhether the cache is active
max_agechrono::Duration5 minutesMax age before forcing a DB lookup
strategyCookieCacheStrategyCompactProtection strategy for the cached payload

CookieCacheStrategy variants:

  • Compact
  • Jwt
  • Jwe

JwtConfig

FieldTypeDefaultDescription
expires_inchrono::Duration1 dayJWT lifetime
algorithmString"HS256"Signing algorithm
issuerOption<String>NoneJWT iss claim
audienceOption<String>NoneJWT aud claim

PasswordConfig

FieldTypeDefaultDescription
min_lengthusize8Minimum password length
require_uppercaseboolfalseRequire uppercase letters
require_lowercaseboolfalseRequire lowercase letters
require_numbersboolfalseRequire digits
require_specialboolfalseRequire special characters
argon2_configArgon2Configsee belowArgon2 tuning

Argon2Config

FieldTypeDefaultDescription
memory_costu324096Memory cost in KiB
time_costu323Iteration count
parallelismu321Degree of parallelism

AccountConfig

FieldTypeDefaultDescription
update_account_on_sign_inbooltrueRefresh stored OAuth account data during sign-in
account_linkingAccountLinkingConfigsee belowAccount-linking behavior
encrypt_oauth_tokensboolfalseEncrypt stored OAuth tokens
store_account_cookieboolfalseStore account data in a cookie for OAuth token flows
store_state_strategyOAuthStateStrategyDatabaseWhere to persist OAuth state
skip_state_cookie_checkboolfalseSkip callback cookie-state verification

AccountLinkingConfig

FieldTypeDefaultDescription
enabledbooltrueEnable account linking
trusted_providersVec<String>[]Providers allowed to auto-link
allow_different_emailsboolfalseAllow linking accounts with different emails
allow_unlinking_allboolfalseAllow unlinking the last linked account
disable_implicit_linkingboolfalseOnly allow explicit linking via link-social
update_user_info_on_linkboolfalseRefresh user info when linking an account

OAuthStateStrategy variants:

  • Cookie
  • Database

AdvancedConfig

FieldTypeDefaultDescription
ip_addressIpAddressConfigsee belowClient IP extraction behavior
disable_csrf_checkboolfalseDisable request-origin / Fetch Metadata CSRF checks
disable_origin_checkboolfalseSkip callback / redirect target origin validation
cross_sub_domain_cookiesOption<CrossSubDomainConfig>NoneShare cookies across subdomains
cookiesHashMap<String, CookieOverride>{}Per-cookie overrides
default_cookie_attributesCookieAttributesall NoneDefault attributes applied to every cookie
cookie_prefixOption<String>NonePrefix applied to every cookie name
databaseAdvancedDatabaseConfigsee belowDatabase-related defaults
trusted_proxy_headersVec<String>[]Headers trusted for real client IP extraction

IpAddressConfig

FieldTypeDefault
headersVec<String>["x-forwarded-for", "x-real-ip"]
disable_ip_trackingboolfalse

CrossSubDomainConfig

FieldTypeDescription
domainStringParent cookie domain such as ".example.com"

CookieAttributes

FieldTypeDefault
secureOption<bool>None
http_onlyOption<bool>None
same_siteOption<SameSite>None
pathOption<String>None
max_ageOption<i64>None
domainOption<String>None

CookieOverride

FieldTypeDefault
nameOption<String>None
attributesCookieAttributesall None

AdvancedDatabaseConfig

FieldTypeDefaultDescription
default_find_many_limitusize100Default limit for "find many" queries
use_number_idboolfalsePrefer numeric generated IDs instead of UUID-like IDs

Plugin-Specific Config

Plugin configs such as EmailPasswordConfig, SessionManagementConfig, OrganizationConfig, PasskeyConfig, and TwoFactorConfig are documented in their plugin guides, because their behavior is best understood next to the routes they affect.

On this page