crates.io ↗

iet-stack-auth-htmx-axum

stack preset official

Statically dispatched account UI presets; applications still own providers.

CoreFeaturesIntegrationsStacksTooling
Used byno framework crate yetexamples/htmx-starterexamples/skills-only-appexamples/skills-only-app-task-tracker
iet-stack-auth-htmx-axumpresetAccount UI preset
Depends oniet-corecontractiet-http-axumcontractiet-auth-login-htmx-axumcontract

How to use it

This stack packages statically dispatched account UI presets. AuthStack::login(auth, csrf) requires only a BrowserLogin and a LoginCsrf; calling .account(provider) additionally enables logout and profile pages through a BrowserFlow provider, while .registration() and .password_recovery() opt into the public flows. The app still owns providers and either registers the stack onto a WebStack (RestApi) or mounts it onto its own Router.

rust
// examples/htmx-starter/servers/web/src/main.rs
use iet_stack_auth_htmx_axum::{AuthStack, StackConfig};

let csrf = Csrf::new()?;
let mut config = StackConfig::default();
config.login.secure_cookies = false;
config.login.session_cookie = "demo_session".into();

let api = AuthStack::login(services.clone(), csrf.clone())
    .account(services.clone()) // logout + profiles via the BrowserFlow provider
    .configuration(config)
    .register(stack)?; // `stack` is a WebStack (iet_http_axum::RestApi)
  • Account starts with registration and recovery disabled; enable them explicitly with .registration() / .password_recovery().
  • routes::<()>() / mount(router) are the alternatives when you already own the axum::Router.
  • StackConfig overrides the route paths and delegates cookie/asset security to LoginConfig.

How it works

AuthStack is generic over a capability state (LoginOnly, then Account<P> once a BrowserFlow provider is attached); register, routes, and mount first validate the configuration, then compose the login routes with the capability's flow routes, and LoginOnly contributes none.

flowchart LR
  L["AuthStack login auth csrf"] --> O["LoginOnly"]
  O --> A["account provider"]
  A --> C["Account with registration and recovery flags"]
  C --> X["configuration StackConfig"]
  X --> P["register or routes or mount"]
  P --> V["validate paths and cookies"]
  V --> R["login register_module or routes_without_assets"]
  V --> F["asset_routes or module_with_policy per flow"]
  R --> OUT["Router or RestApi"]
  F --> OUT

What it implements

  • Concrete mechanism; see the public API below.

What's inside

Modules

  • src/capabilities.rs
  • src/config.rs
  • src/lib.rs
  • src/stack.rs

Public API

capabilities

  • struct LoginOnly — Login-only capability state: does not require a BrowserFlow provider.
  • struct Account — Explicit account capabilities. Registration/recovery are disabled initially.
  • trait Capability
rust
pub trait Capability {
    fn register<S, C, L>(
        self,
        api: iet_http_axum::RestApi<S, L>,
        csrf: C,
        config: &StackConfig,
    ) -> AppResult<iet_http_axum::RestApi<S, L>>
    where
        S: Clone + Send + Sync + 'static,
        C: LoginCsrf + Clone + Send + Sync + 'static,
        L: iet_http_axum::RateLimit;
    fn paths<'a>(&self, config: &'a StackConfig) -> Vec<(Flow, &'a str)>;
    fn mount<S, C>(self, router: Router<S>, csrf: C, config: &StackConfig) -> AppResult<Router<S>>
    where
        S: Clone + Send + Sync + 'static,
        C: LoginCsrf + Clone + Send + Sync + 'static;
}

config

  • struct StackConfig

stack

  • struct AuthStack
  • pub fn login(auth: A, csrf: C) -> Self
  • pub fn account<P: BrowserFlow>(self, provider: P) -> AuthStack<A, C, Account<P>> — Explicitly enable logout and profiles; does not enable public signup or recovery.
  • pub fn registration(mut self) -> Self
  • pub fn password_recovery(mut self) -> Self
  • pub fn configuration(mut self, config: StackConfig) -> Self
  • pub fn routes<S>(self) -> AppResult<Router<S>> where S: Clone + Send + Sync + 'static,
  • pub fn register<S, L>(self, api: RestApi<S, L>) -> AppResult<RestApi<S, L>> where L: iet_http_axum::RateLimit, S: Clone + Send + Sync + 'static, — Adds one named module; caller retains body limits, state and manual registrations.
  • pub fn mount<S>(self, router: Router<S>) -> AppResult<Router<S>> where S: Clone + Send + Sync + 'static,

Impl map

  • Capability for LoginOnly
  • Capability for Account<P>
  • Default for StackConfig

Depends on

External crates: axum

Used by

  • No other framework crate depends on it directly.

In this repository

  • examples/htmx-starter
  • examples/skills-only-app
  • examples/skills-only-app-task-tracker

Source: crates/stacks/iet-stack-auth-htmx-axum