pub struct BetterAuthCompat { /* private fields */ }Expand description
Runs fastauth on a database a Better Auth app also uses, and lets the two share sign-ins:
FastAuth::builder().better_auth_compat(BetterAuthCompat::new(secret).cookie_prefix("vt")).
Applied at .build(), where it overrides the matching settings:
- cookies are named
{prefix}.session_token(__Secure-in front on https) and signed in Better Auth’s format with the raw secret (CookieSigning::BetterAuth); - sessions last
BetterAuthCompat::expires_in(14 days unless set) and are extended onceBetterAuthCompat::update_age(one day) has passed since their last extension, by Better Auth’s rule (SlidingRefresh::ExpiresAt); - passwords use
BetterAuthScrypt, at mostBetterAuthCompat::max_concurrent_hashesat a time; - columns are stored in Better Auth’s names:
ColumnNaming::CamelCase, the password hash inaccount.password, and the OAuth tokens as hex in its text columns. The tokens stay encrypted: storing them as plain text, as Better Auth does, is a separate choice (Builder::store_oauth_tokens_in_plaintext) the preset never makes; - sessions are stored with their raw token (
SessionTokens::Raw), so each app resolves the other’s sessions; - fastauth leaves
accountrows of providers it doesn’t own alone (Builder::only_owned_accounts); - the migrator is review-only (
Migrations::ReviewOnly):fastauth generatewrites the SQL to review,fastauth migraterefuses.
fastauth’s verification rows don’t fit Better Auth’s verification table, so give them
their own on the adapter: Sqlx::new(pool).rename("verification", "fastauth_verification").
The cookie cache can’t be used with it: .build() refuses SessionConfig::cookie_cache.
fastauth’s own .secret(..) is still needed; it keys everything that isn’t a cookie
(encrypted columns, plugin keys, rate-limit buckets).
Implementations§
Source§impl BetterAuthCompat
impl BetterAuthCompat
Sourcepub fn new(secret: impl Into<Vec<u8>>) -> Self
pub fn new(secret: impl Into<Vec<u8>>) -> Self
The Better Auth app’s secret (BETTER_AUTH_SECRET), as the app has it: its UTF-8 bytes
key the cookie HMAC, with no decoding and no key derivation.
Sourcepub fn from_env(var: &str) -> Result<Self, BuildError>
pub fn from_env(var: &str) -> Result<Self, BuildError>
BetterAuthCompat::new with the value of an environment variable, read as it is.
Unlike Secret::from_env, a value that happens to be valid base64 isn’t decoded.
The Better Auth app’s advanced.cookiePrefix (default "better-auth").
Sourcepub fn expires_in(self, d: Duration) -> Self
pub fn expires_in(self, d: Duration) -> Self
The Better Auth app’s session.expiresIn (14 days unless set; Better Auth’s own
default is 7). Both apps should use the same value, since each extends a session to
its own.
Sourcepub fn update_age(self, d: Duration) -> Self
pub fn update_age(self, d: Duration) -> Self
The Better Auth app’s session.updateAge (one day, Better Auth’s default).
Sourcepub fn max_concurrent_hashes(self, n: usize) -> Self
pub fn max_concurrent_hashes(self, n: usize) -> Self
How many scrypt hashes run at once at most (default 8, and never more than the number of CPUs): 32 MiB each, so 256 MiB at most by default.