fastauth-core 0.1.0

Core of fastauth: the builder, plugin system, sessions, crypto and routing.
Documentation

fastauth

Authentication for Rust web apps, modelled on Better Auth: one builder call gives you email and password sign-in, social login, sessions, and a plugin system for two-factor, organizations, passkeys, API keys and the rest. It runs on sqlx and axum out of the box, and the plugin API is checked by the compiler.

Status: v0.1. Core, axum, sqlx (Postgres and SQLite), the derive macros, GitHub and Google sign-in, two-factor and the CLI are published on crates.io and tested, including against Better Auth's own client. Some pages in docs/ still describe planned features (organization, passkey, admin, actix, Redis); docs/01 lists what ships.

use fastauth::prelude::*;
use fastauth::plugins::{organization::Organization, two_factor::TwoFactor};
use fastauth::social::{Github, Social};

pub type AppAuth = Auth<Sqlx<Postgres>, Profile, plugins![Social, TwoFactor, Organization]>;

#[derive(Fields, Serialize, Clone)]
pub struct Profile {
    #[field(default = "free")]
    pub plan: String,
}

pub fn auth(pool: PgPool) -> Result<AppAuth, BuildError> {
    FastAuth::builder()
        .secret(Secret::from_env("FASTAUTH_SECRET")?)
        .base_url("http://localhost:3000")
        .database(Sqlx::new(pool))
        .email_password(EmailPassword::default())
        .user_fields::<Profile>()
        .plugin(Social::new().provider(Github::from_env()?))
        .plugin(TwoFactor::new().issuer("Acme"))
        .plugin(Organization::default())
        .build()
}

async fn me(session: Session<AppAuth>) -> Json<Value> {
    let tfa = session.user.plugin::<TwoFactor, _>();
    Json(json!({
        "email": session.user.email,
        "plan": session.user.fields.plan,
        "twoFactor": tfa.two_factor_enabled,
    }))
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let pool = PgPool::connect(&std::env::var("DATABASE_URL")?).await?;
    let auth = auth(pool)?;
    auth.migrator().run().await?;

    let app = Router::new()
        .route("/me", get(me))
        .merge(auth.router()) // serves /api/auth/*
        .with_state(auth);

    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?;
    axum::serve(listener, app).await?;
    Ok(())
}

If you remove TwoFactor from the builder, session.user.plugin::<TwoFactor, _>() stops compiling and tells you which plugin is missing.

Docs

Page What it covers
Overview Goals, non-goals, crate layout, feature flags, the main design decisions
Quickstart From cargo new to sign-up, sign-in and a protected route
Configuration Every builder option: secrets, email and password, social providers, sessions, cookies, rate limits
Sessions and the server API Extractors, typed user fields, calling auth from your own code
Plugins Using plugins, and writing one: schema, endpoints, hooks, events, errors, dependencies
Databases The adapter trait, typed models, sqlx, migrations, writing an adapter
HTTP integrations axum, actix-web, raw tower, the outgoing HTTP client, writing an integration
Internals How it works: the type-level plugin list, the build step, the request path, the session hot path
Security Tokens, cookies, password hashing, CSRF, OAuth, rate limiting, secret rotation
Open questions Decisions that need an owner before v0.1
Better Auth's client Using better-auth/client with fastauth, the tested version, known gaps

Agent skill

skills/use-fastauth teaches coding agents to use fastauth in their own apps: setup, axum, migrations, user fields, the first-party plugins, the server API, custom plugins and tests, plus the compiler errors they'll meet. Every code sample in it compiles against main. Copy the folder into your agent's skills directory (for Claude Code, .claude/skills/use-fastauth/).