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:
| Feature | Adds |
|---|---|
axum (default) | fastauth::axum: auth.router(), the Session extractors, the session layer |
postgres (default), sqlite | fastauth::sqlx: Sqlx::new(pool), and the pool types in the prelude |
macros (default) | #[derive(Fields, Model, AuthError)] |
oauth | fastauth::social: the Social plugin with GitHub and Google |
two-factor | fastauth::plugins::two_factor: TOTP, email OTP, backup codes |
organization | fastauth::plugins::organization: organizations, members, invitations, roles |
admin | fastauth::plugins::admin: roles, bans, impersonation, user management |
api-key | fastauth::plugins::api_key: per-user API keys |
cli | fastauth::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;
Modules§
- adapter
- The database contract. See
docs/06-database.md. - cli
- The commands behind your app’s
fastauthbinary:schema,status,generateandmigrate. Seedocs/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::withindefer them to aDeferredEventsqueue. - internal
- Core operations shared by core endpoints and plugins: users, accounts, sessions, sign-in with gates, verification values, email.
- Auth emails. A
Mailerturns 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]isCons<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). - Auth
Error - The one error type every endpoint, hook and extractor returns. It leaves the server as
{ "code": "...", "message": "..." }withstatus. - Build
Error - Configuration problems found by
.build(), all reported at once. - Builder
- Collects configuration.
.build()only exists oncesecret,base_urlanddatabaseare set: the last three type parameters track that. - Client
Addr - The client’s socket address. Integrations put it in request extensions.
- Cons
- A plugin followed by the rest of the list.
- Fast
Auth - 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![..]. - Auth
Instance - 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 anAuththat registered the plugin. - Plugin
Set - 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
SignedDurationunder its original name.
Derive Macros§
- Auth
Error - Implements
From<E> for AuthErrorandErrorCodesfor an enum of plugin errors. - Fields
- Implements
FieldsandOnTablefor a struct of columns added to an existing table, plus a typedColconstant per field (two_factor_enabledbecomesTWO_FACTOR_ENABLED). - Model
- Implements
ModelandOnTable<Table = Self>for a table, plus a typedColconstant per field.