pub struct Builder<D, U, P, S, B> { /* private fields */ }Expand description
Collects configuration. .build() only exists once secret, base_url and database
are set: the last three type parameters track that.
Implementations§
Source§impl<D, U, P, S, B> Builder<D, U, P, S, B>
impl<D, U, P, S, B> Builder<D, U, P, S, B>
Sourcepub fn secret(self, secret: Secret) -> Builder<D, U, P, Present, B>
pub fn secret(self, secret: Secret) -> Builder<D, U, P, Present, B>
The master secret (at least 32 bytes). See Secret::from_env.
Sourcepub fn secrets(
self,
secrets: impl IntoIterator<Item = Secret>,
) -> Builder<D, U, P, Present, B>
pub fn secrets( self, secrets: impl IntoIterator<Item = Secret>, ) -> Builder<D, U, P, Present, B>
Several secrets for rotation: the first signs, all verify.
Sourcepub fn base_url(self, url: impl Into<String>) -> Builder<D, U, P, S, Present>
pub fn base_url(self, url: impl Into<String>) -> Builder<D, U, P, S, Present>
The public URL of the app, e.g. https://acme.dk.
pub fn app_name(self, name: impl Into<String>) -> Self
Sourcepub fn base_path(self, path: impl Into<String>) -> Self
pub fn base_path(self, path: impl Into<String>) -> Self
Where auth routes live (default /api/auth).
Sourcepub fn trusted_origins(
self,
origins: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn trusted_origins( self, origins: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Origins allowed to make cookie-carrying requests and to be redirect targets.
pub fn email_password(self, config: EmailPassword) -> Self
pub fn email_verification(self, config: EmailVerification) -> Self
pub fn session(self, config: SessionConfig) -> Self
pub fn rate_limit(self, config: RateLimit) -> Self
pub fn client_ip(self, source: ClientIp) -> Self
Sourcepub fn ids(self, strategy: IdStrategy) -> Self
pub fn ids(self, strategy: IdStrategy) -> Self
How ids are generated and stored; IdStrategy::Ulid unless set.
Apps upgrading a Postgres database created by fastauth 0.1 (uuid id columns)
keep it working with .ids(IdStrategy::UuidV7).
pub fn mailer(self, mailer: impl Mailer) -> Self
Sourcepub fn secondary_storage(self, storage: impl SecondaryStorage) -> Self
pub fn secondary_storage(self, storage: impl SecondaryStorage) -> Self
A key-value store every instance of the app shares, such as Redis
(fastauth_redis::RedisStorage). Rate limit counters live there, so a limit holds
across all instances. Without it, each instance keeps its own counters in memory.
Each call is bounded by secondary_storage_timeout.
A call that fails or times out falls back to this instance’s in-memory limiter, and
after 5 such calls in a row the storage is skipped for 5 seconds before one request
probes it again, so a dead store doesn’t slow every request down.
Sourcepub fn secondary_storage_timeout(self, timeout: Duration) -> Self
pub fn secondary_storage_timeout(self, timeout: Duration) -> Self
How long a request waits for one secondary storage call before its rate limit falls
back to this instance’s memory. Default: 100 ms
(DEFAULT_STORAGE_TIMEOUT).
Sourcepub fn multi_instance(self, multi_instance: bool) -> Self
pub fn multi_instance(self, multi_instance: bool) -> Self
Says the app runs as several instances (processes, containers, machines) behind a
load balancer. .build() then warns when rate limiting is on without
secondary_storage, since each instance would allow the
full limit.
Sourcepub fn allow_insecure_config(self, allow: bool) -> Self
pub fn allow_insecure_config(self, allow: bool) -> Self
Builds a configuration that .build() refuses for production, logging each problem
as a warning instead: an http:// base_url on a host other than localhost, or a
current (first) secret with too little entropy. A weak retired secret is only ever
logged, so rotating off one needs no opt-out. For local development, CI and staging setups on a
private network only. A localhost base_url gets the same leniency without it.
Sourcepub fn column_naming(self, naming: ColumnNaming) -> Self
pub fn column_naming(self, naming: ColumnNaming) -> Self
How column names are stored in the database, for every table: core’s, the plugins’
and the app’s fields. ColumnNaming::CamelCase stores email_verified as
emailVerified, as Better Auth does. Code keeps using the declared names
(User::EMAIL_VERIFIED, #[derive(Fields)] field names); only the SQL changes.
Default: ColumnNaming::SnakeCase, the declared names.
Sourcepub fn rename_column(
self,
table: impl Into<String>,
column: impl Into<String>,
to: impl Into<String>,
) -> Self
pub fn rename_column( self, table: impl Into<String>, column: impl Into<String>, to: impl Into<String>, ) -> Self
Stores table.column (declared names) as to, over the naming strategy:
.rename_column("account", "password_hash", "password") keeps the password hash in
Better Auth’s password column. .build() fails on a column the schema doesn’t have.
Sourcepub fn bytes_as_hex_text(
self,
table: impl Into<String>,
column: impl Into<String>,
) -> Self
pub fn bytes_as_hex_text( self, table: impl Into<String>, column: impl Into<String>, ) -> Self
Stores the byte column table.column as lowercase hex text, for a text column
another app created, such as Better Auth’s account.accessToken. The values stay
what they are (access_token is still encrypted); only their encoding changes.
Text that isn’t hex, which only the other app writes, reads as its UTF-8 bytes.
Sourcepub fn session_tokens(self, tokens: SessionTokens) -> Self
pub fn session_tokens(self, tokens: SessionTokens) -> Self
How session tokens are stored: SessionTokens::Hashed (the default) or
SessionTokens::Raw, the token itself in session.token, as Better Auth stores
it. Raw tokens let both apps resolve each other’s sessions while they share a
database, and give up the protection hashing gives a leaked table; see
docs/concepts/03-security.md.
Sourcepub fn only_owned_accounts(self, on: bool) -> Self
pub fn only_owned_accounts(self, on: bool) -> Self
Leaves account rows of providers fastauth doesn’t own alone: it never reads them
as a sign-in method, lists, changes, unlinks or deletes them, and refuses to delete a
user that has one (409 USER_HAS_FOREIGN_ACCOUNTS, since the foreign key would
delete it too). fastauth owns credential and the providers plugins register (each
social provider). For a database another app writes accounts to, such as the
oidc rows of an SSO integration. Off by default: fastauth manages every row.
Sourcepub fn store_oauth_tokens_in_plaintext(self, on: bool) -> Self
pub fn store_oauth_tokens_in_plaintext(self, on: bool) -> Self
Stores the OAuth access and refresh tokens providers return as plain text instead of
encrypting them with the secret, as Better Auth does unless its
account.encryptOAuthTokens is on. For a database a Better Auth app shares: its
/get-access-token, and app code reading account.accessToken, then get the
provider’s token after a sign-in through fastauth, not fastauth’s ciphertext. A token
column stored as text (bytes_as_hex_text, which
BetterAuthCompat sets) then holds the token itself rather than hex
(BytesText::Utf8). The id token is stored as it
is either way.
Rows already stored aren’t rewritten; Account::read_access_token reads both kinds.
Anyone who can read the table, a backup or a replica can call the provider as the user,
so turn it on only for the migration window; BetterAuthCompat doesn’t. Off by
default: tokens are encrypted.
Sourcepub fn migrations(self, mode: Migrations) -> Self
pub fn migrations(self, mode: Migrations) -> Self
Whether auth.migrator() may change the database. Migrations::ReviewOnly makes
run and apply (and fastauth migrate) refuse, for a schema another app’s
migrations own, and fastauth generate write each step as its own migration to
review. Default: Migrations::Apply.
Sourcepub fn better_auth_compat(self, compat: BetterAuthCompat) -> Self
pub fn better_auth_compat(self, compat: BetterAuthCompat) -> Self
Shares sessions and passwords with a Better Auth app on the same database: Better
Auth’s cookie format and secret, its session refresh and its scrypt password hashes.
Applied at .build(), over the matching cookie, session and email-and-password
settings. See BetterAuthCompat.
Sourcepub fn user_fields<U2: Fields>(self) -> Builder<D, U2, P, S, B>
pub fn user_fields<U2: Fields>(self) -> Builder<D, U2, P, S, B>
The app’s own columns on user.