modo-session-0.1.0 has been yanked.
modo-session
Database-backed HTTP session management for the modo framework.
Sessions are identified by a ULID, authenticated via a cryptographically random
32-byte token stored in a browser cookie, and persisted in the modo_sessions
table. Only the SHA-256 hash of the token is written to the database. A
server-side fingerprint (SHA-256 of User-Agent + Accept-Language +
Accept-Encoding) is used to detect session hijacking.
Features
| Feature | Description |
|---|---|
cleanup-job |
Registers a modo-jobs cron job that deletes expired sessions every 15 minutes. Requires modo-jobs. |
Usage
Register the middleware
use ;
// In your app entry point:
let session_store = new;
app.service
.layer
.run
.await?;
Registering the store as a .service() makes it available to background jobs
(e.g. the cleanup-job).
Authentication
use SessionManager;
async
async
Logout
async
Reading session state
async
Session data (key/value store)
async
async
Reading user ID from other middleware
When you need the current user ID inside a Tower layer (not a handler), use the non-blocking helper:
use user_id_from_extensions;
let user_id = user_id_from_extensions;
Configuration
SessionConfig deserialises from YAML/TOML with #[serde(default)]:
session_ttl_secs: 2592000 # 30 days (default)
cookie_name: "_session" # default
validate_fingerprint: true # default
touch_interval_secs: 300 # 5 minutes (default)
max_sessions_per_user: 10 # default; LRU eviction when exceeded
trusted_proxies: # default: empty (trust all proxy headers)
- "10.0.0.0/8"
Key Types
| Type | Description |
|---|---|
SessionConfig |
Tunable parameters: TTL, cookie name, fingerprint, proxies. |
SessionStore |
Low-level DB store; use as a managed service for background jobs. |
SessionManager |
Axum extractor for request-scoped session operations. |
SessionData |
Full session record (ID, user, device info, JSON payload, timestamps). |
SessionId |
Opaque ULID-based session identifier. |
SessionToken |
32-byte random token; serialises as hex; Debug/Display are redacted. |
SessionMeta |
Request metadata (IP, UA, device) captured by the middleware. |
layer |
Creates the Tower middleware layer from a SessionStore. |
user_id_from_extensions |
Non-blocking helper to read user ID in Tower layers. |