Skip to main content

Module middleware

Module middleware 

Source
Expand description

Tower middleware layer that loads, validates, and persists sessions for every request.

The public entry point is layer, which wraps a SessionStore in a Tower Layer / Service pair. The middleware:

  1. Reads the session token from the request cookie.
  2. Loads the matching, non-expired session from the database.
  3. Optionally validates a server-side request fingerprint.
  4. Injects shared state so the crate::SessionManager extractor can operate within the handler.
  5. After the handler returns, applies any pending session action (set cookie, remove cookie, or touch expiry).

Structs§

SessionContextLayer
Tower Layer produced by layer.
SessionMiddleware
Tower Service produced by SessionContextLayer.

Functions§

layer
Create a session middleware layer from a SessionStore.
user_id_from_extensions
Extract the current user ID from request extensions without going through the full crate::SessionManager extractor.