Skip to main content

require_auth

Function require_auth 

Source
pub async fn require_auth<S>(
    state: State<S>,
    request: Request<Body>,
    next: Next,
) -> Response
where Arc<dyn AuthClient>: FromRef<S>, S: Send + Sync + Clone,
Expand description

Axum middleware that requires a valid authenticated session.

Validates the session cookie, fetches the user, and inserts the User into request extensions so downstream handlers can access it cheaply via Extension<User>. Returns 401 JSON on any authentication failure.

Apply to a route group with axum::middleware::from_fn_with_state(ath, require_auth).