Server-side sessions and remember-me: which implementation would you accept? (follow-up to #561 / #633)
Feature Request
Is your feature request related to a problem? Please describe.
Loco has no server-side sessions today. The recommended path for browser apps is a JWT read from a cookie (JWTLocation::Cookie), which works for authentication but leaves two gaps for server-rendered and Inertia/HTMX apps:
- No revocation. A session can't be ended from the server (log a user out, "sign out of all devices", lock an account) without building a token denylist.
- No real remember-me. It can only be approximated with a longer JWT expiry, with the same revocation problem.
Rails, Laravel and Django all ship sessions and remember-me out of the box. For "Rust on Rails", it's probably the most visible missing piece when building a classic web app.
This was discussed in #561, where @jondot outlined a direction I think is still right: an encrypted and signed cookie store by default in development, and a server-side store required in production. #633 implemented a version of it with tower-sessions. It was closed without merging, with the comment that the team needed "to think through a better implementation", and #561 was later closed without a session module landing.
Describe the solution you'd like
Rather than propose one design and have it rejected again, I'd like to ask what shape you would accept. A starting point:
- Sessions: a
Sessionextractor backed bytower-sessions, with the store chosen in config (cookie for development, database or Redis for production), and with the release/production guard from #561. - Remember-me: a long-lived random token stored hashed in the database and rotated on use, the way Rails and Laravel do it, so it can be revoked individually or all at once.
- Auth integration: an extractor, alongside
auth::JWT, that resolves the current user from the session or the remember-me token.
Open questions for you:
- Is
tower-sessionsacceptable as the foundation, or would you rather own the implementation? - Should the default store for production be the database (no extra infrastructure) or Redis?
- Should this land in core, or as an initializer/extension crate like
loco-openapi-initializer? - What was missing in #633, so a new attempt doesn't repeat it?
Happy to test an implementation and give feedback from a real app that needs it.
Describe alternatives you've considered
- JWT in a cookie (current approach): no server-side revocation, and remember-me is only a longer expiry.
- Adding
tower-sessionsas a layer per project: it works, since Loco is Axum underneath, but every app rebuilds the same config, store setup, auth integration and remember-me logic, which is the kind of convention a batteries-included framework usually owns.
Source: loco-rs/loco