Skip to main content

Crate fastauth

Crate fastauth 

Source
Expand description

Authentication for Rust web apps, modelled on Better Auth.

This is the crate apps depend on. It re-exports fastauth_core and, behind features, everything else:

FeatureAdds
axum (default)fastauth::axum: auth.router(), the Session extractors, the session layer
postgres (default), sqlitefastauth::sqlx: Sqlx::new(pool), and the pool types in the prelude
macros (default)#[derive(Fields, Model, AuthError)]
oauthfastauth::social: the Social plugin with GitHub and Google
two-factorfastauth::plugins::two_factor: TOTP, email OTP, backup codes
organizationfastauth::plugins::organization: organizations, members, invitations, roles
adminfastauth::plugins::admin: roles, bans, impersonation, user management
api-keyfastauth::plugins::api_key: per-user API keys
clifastauth::cli: schema, status, generate and migrate for your app’s binary

crates/fastauth/examples/axum_sqlite.rs is a complete app.

Re-exports§

pub use fastauth_axum as axum;
pub use fastauth_sqlx as sqlx;
pub use fastauth_oauth as social;

Modules§

adapter
The database contract. See docs/06-database.md.
cli
The commands behind your app’s fastauth binary: schema, status, generate and migrate. See docs/06-database.md.
config
cookies
Cookie parsing and Set-Cookie building.
crypto
Secrets, derived keys, signing, encryption, hashing and password hashing. See docs/09-security.md.
endpoint
Endpoints, the request context, hooks, and the execution pipeline shared by HTTP requests and server-side API calls.
error
events
Events fire after an endpoint succeeds, for every caller (HTTP, server API, plugins). Server API calls made with Api::within defer them to a DeferredEvents queue.
internal
Core operations shared by core endpoints and plugins: users, accounts, sessions, sign-in with gates, verification values, email.
mail
Auth emails. A Mailer turns each typed email into a message.
memory
An in-memory adapter for tests and examples. Not for production: no durability, and a transaction is a snapshot that overwrites the store on commit.
migrate
Diffs the configured schema against the live database. Only ever adds.
model
models
Core tables: user, session, account, verification.
plugin
The plugin trait and the registration API plugins (and the app) use in init.
plugin_prelude
Everything a plugin author needs.
plugins
First-party plugins.
prelude
Everything an app needs to configure auth.
query
The typed query builder plugins use through ctx.db().
rate_limit
GCRA rate limiting: one timestamp per key, in sharded in-memory maps.
routes
Core endpoints. Paths and JSON shapes follow Better Auth, so its client works unchanged.
schema
session
Session lookup (cookie, cookie cache, resolvers), refresh, and the typed session the app sees.
value

Macros§

plugins
plugins![A, B] is Cons<A, Cons<B, Nil>>: the plugin list in registration order.

Structs§

Api
Server-side endpoint calls. Pass the request’s headers (or a session token) for endpoints that need a session.
ApiResponse
An endpoint’s typed output plus the cookies it wants set.
Auth
A configured auth instance. Cheap to clone (two Arcs).
AuthError
The one error type every endpoint, hook and extractor returns. It leaves the server as { "code": "...", "message": "..." } with status.
BuildError
Configuration problems found by .build(), all reported at once.
Builder
Collects configuration. .build() only exists once secret, base_url and database are set: the last three type parameters track that.
ClientAddr
The client’s socket address. Integrations put it in request extensions.
Cons
A plugin followed by the rest of the list.
FastAuth
Entry point: FastAuth::builder().
Here
Index: the plugin is the head.
Missing
Builder state: a required option is missing.
Nil
The empty plugin list.
NoDatabase
Builder state: no database yet.
Present
Builder state: a required option is set.
There
Index: the plugin is in the tail.

Traits§

Append
Appends at the end, so the list reads in registration order like plugins![..].
AuthInstance
What integrations and plugin extension traits need from an auth instance, without naming its type parameters.
Has
HasPlugin
For plugin extension traits: methods bounded by Self: HasPlugin<MyPlugin, I> only compile on an Auth that registered the plugin.
PluginSet
Walks the list: registration at build time, decoding on every session load.
Satisfied
A tuple of plugins that must all be in list L. Checked by .plugin(..).

Type Aliases§

Duration
A SignedDuration under its original name.

Derive Macros§

AuthError
Implements From<E> for AuthError and ErrorCodes for an enum of plugin errors.
Fields
Implements Fields and OnTable for a struct of columns added to an existing table, plus a typed Col constant per field (two_factor_enabled becomes TWO_FACTOR_ENABLED).
Model
Implements Model and OnTable<Table = Self> for a table, plus a typed Col constant per field.