Skip to main content

AuthConfig

Struct AuthConfig 

Source
pub struct AuthConfig {
Show 23 fields pub secret: String, pub managed_secrets: Option<ManagedSecrets>, pub app_name: String, pub base_url: String, pub dynamic_base_url: Option<DynamicBaseUrl>, pub trusted_origins_resolver: Option<Arc<dyn TrustedOriginsResolver>>, pub base_path: String, pub trusted_origins: Vec<String>, pub disabled_paths: Vec<String>, pub render_error_page: bool, pub api_error_url: Option<String>, pub throw_api_errors: bool, pub session: SessionConfig, pub user: UserConfig, pub verification: VerificationConfig, pub jwt: JwtConfig, pub password: PasswordConfig, pub account: AccountConfig, pub email_provider: Option<Arc<dyn EmailProvider>>, pub background_tasks: Option<Arc<dyn BackgroundTaskHandler>>, pub awaited_notification_errors: AwaitedNotificationErrorPolicy, pub user_validation: Option<Arc<dyn UserInfoValidator>>, pub advanced: AdvancedConfig,
}
Expand description

Main configuration for Alibi

Fields§

§secret: String

Single-secret input. Managed mode uses current_secret() instead.

§managed_secrets: Option<ManagedSecrets>

Versioned encryption keys. When present, its current key signs new tokens. Bare encrypted values require an explicitly configured legacy key.

§app_name: String

Application name, used for cookie prefixes, email templates, etc.

Defaults to "Better Auth".

§base_url: String

Base URL for the authentication service (e.g. "http://localhost:3000").

§dynamic_base_url: Option<DynamicBaseUrl>

Request-dependent host allowlist. Static base_url remains the default.

§trusted_origins_resolver: Option<Arc<dyn TrustedOriginsResolver>>

Application callback resolving additional trusted origins from the real request.

§base_path: String

Base path where the auth routes are mounted.

All routes handled by Alibi will be prefixed with this path. For example, with the default "/api/auth", the sign-in route becomes "/api/auth/sign-in/email".

Defaults to "/api/auth".

§trusted_origins: Vec<String>

Origins that are trusted for CSRF and other cross-origin checks.

Supports glob patterns (e.g. "https://*.example.com"). These are shared across all middleware that needs origin validation (CSRF, CORS, etc.).

§disabled_paths: Vec<String>

Paths that should be disabled (skipped) by the router.

Any request whose path matches an entry in this list will receive a 404 response, even if a handler is registered for it.

§render_error_page: bool

Render the built-in HTML page for GET /error instead of redirecting to /.

Defaults to false when NODE_ENV is production, and true otherwise. Set this to true to enable the renderer in production, corresponding to upstream’s explicit onAPIError.customizeDefaultErrorPage option.

§api_error_url: Option<String>

Default OAuth error destination, corresponding to onAPIError.errorURL.

§throw_api_errors: bool

Propagate ordinary endpoint failures to the hosting application. Explicit public API errors continue to return HTTP responses.

§session: SessionConfig

Session configuration

§user: UserConfig

Application user-field input, adapter and public output policies.

§verification: VerificationConfig

Verification storage lifecycle settings.

§jwt: JwtConfig

JWT configuration

§password: PasswordConfig

Password configuration

§account: AccountConfig

Account configuration (linking, token encryption, etc.)

§email_provider: Option<Arc<dyn EmailProvider>>

Email provider for sending emails (verification, password reset, etc.)

§background_tasks: Option<Arc<dyn BackgroundTaskHandler>>

Observe already running deferred operations. Ignoring their completion does not cancel them; applications may retain completions for shutdown.

§awaited_notification_errors: AwaitedNotificationErrorPolicy

Error handling when the request awaits a lifecycle notification.

§user_validation: Option<Arc<dyn UserInfoValidator>>

Validate fresh identity data before its creation hooks or provider account/session writes. Returning non-provider sign-ins are unchanged.

§advanced: AdvancedConfig

Advanced configuration options

Implementations§

Source§

impl AuthConfig

Source

pub fn dynamic_base_url(self, config: DynamicBaseUrl) -> Self

Source

pub fn trusted_origins_resolver( self, resolver: impl TrustedOriginsResolver + 'static, ) -> Self

Source

pub fn trusted_providers_resolver( self, resolver: impl TrustedProvidersResolver + 'static, ) -> Self

Replace static account-linking trust with an async application policy.

Source

pub async fn resolve_request(&self, request: &AuthRequest) -> AuthResult<Self>

Resolve the URL and origin policy without mutating the shared instance.

§Errors

Fails when no permitted host or fallback exists, the fallback is invalid, or an application trust resolver fails.

Source§

impl AuthConfig

Source

pub const fn awaited_notification_errors( self, policy: AwaitedNotificationErrorPolicy, ) -> Self

Choose whether awaited lifecycle email delivery failures fail the request.

Source

pub fn background_tasks(self, handler: Arc<dyn BackgroundTaskHandler>) -> Self

Integrate deferred task completions with the application executor.

Source

pub fn new(secret: impl Into<String>) -> Self

Source

pub fn app_name(self, name: impl Into<String>) -> Self

Set the application name.

Source

pub fn base_url(self, url: impl Into<String>) -> Self

Set the base URL (e.g. "https://myapp.com").

Also updates session.cookie_secure to match the URL scheme: HTTPS URLs set Secure=true, HTTP URLs set Secure=false.

Source

pub fn account(self, account: AccountConfig) -> Self

Source

pub fn api_error_url(self, url: impl Into<String>) -> Self

Configure the default OAuth error destination (onAPIError.errorURL). An empty value uses the endpoint’s ordinary fallback.

Source

pub fn base_path(self, path: impl Into<String>) -> Self

Set the base path where auth routes are mounted.

Source

pub fn trusted_origin(self, origin: impl Into<String>) -> Self

Add a trusted origin. Supports glob patterns (e.g. "https://*.example.com").

Source

pub fn trusted_origins(self, origins: Vec<String>) -> Self

Set all trusted origins at once.

Source

pub fn disabled_path(self, path: impl Into<String>) -> Self

Add a path to the disabled paths list.

Source

pub fn disabled_paths(self, paths: Vec<String>) -> Self

Set all disabled paths at once.

Source

pub const fn throw_api_errors(self, enabled: bool) -> Self

Propagate ordinary endpoint exceptions through the public request result.

Source

pub const fn session_expires_in(self, duration: Duration) -> Self

Set the session expiration duration.

Source

pub const fn session_update_age(self, duration: Duration) -> Self

Source

pub const fn disable_session_refresh(self, disabled: bool) -> Self

Source

pub const fn session_fresh_age(self, duration: Duration) -> Self

Set the cookie cache configuration for sessions.

Source

pub const fn jwt_expires_in(self, duration: Duration) -> Self

Set the JWT expiration duration.

Source

pub fn advanced(self, advanced: AdvancedConfig) -> Self

Source

pub fn cookie_prefix(self, prefix: impl Into<String>) -> Self

Source

pub const fn disable_csrf_check(self, disabled: bool) -> Self

Source

pub fn current_secret(&self) -> &str

Current key for signing tokens and cookies. Retained keys are encryption readers; signed cookies and signed JWTs deliberately use only this key.

Source

pub fn verification_secrets(&self) -> impl Iterator<Item = &str>

Encryption readers in configured order, followed by a distinct legacy key.

Source

pub fn managed_secrets(self, secrets: ManagedSecrets) -> Self

Enable managed encryption with an explicit current version and readers.

Source

pub fn origin_check_disabled_for(&self, path: &str) -> bool

Determine whether this request path opts out of origin validation.

Source

pub fn current_origin_check_disabled(&self) -> bool

Apply the configured origin policy at an initialized request callback.

Source

pub const fn disable_origin_check(self, disabled: bool) -> Self

Source

pub fn cross_sub_domain_cookies(self, domain: impl Into<String>) -> Self

Source

pub fn cross_sub_domain_cookies_from_base_url(self) -> Self

Share cookies using the configured or request-resolved base URL’s hostname. This follows the published hostname directly; it does not infer a parent or registrable domain. Use cross_sub_domain_cookies when a deployment needs an explicit parent domain.

Source

pub fn is_origin_trusted(&self, origin: &str) -> bool

Check the resolved base origin or a configured trusted pattern.

Explicit patterns follow Better Auth 1.7.6: * and ? match URL origins (or hosts for patterns without a scheme), while custom schemes retain authority and normalized path-prefix constraints. Resolve dynamic policies with resolve_request before evaluating them.

Source

pub fn is_redirect_target_trusted(&self, url: &str) -> bool

Check whether a URL is a safe redirect target.

A URL is safe if it is a relative path (starts with /, no traversal tricks) or its origin matches base_url or trusted_origins.

This is used by both the CSRF middleware (for POST body/query targets) and per-endpoint origin checks (e.g. verify-email GET).

Source

pub fn is_path_disabled(&self, path: &str) -> bool

Check whether a given path is disabled.

Source

pub fn validate(&self) -> Result<(), AuthError>

§Errors

Returns a configuration error if the signing secret is empty or shorter than 32 bytes.

Trait Implementations§

Source§

impl Clone for AuthConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AuthConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AuthConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more