maxcountryman / axum-sessions

🥠 Cookie-based sessions for Axum via async-session.
MIT License
74 stars 18 forks source link

initial sketch for `session.regenerate()` support #6

Closed maxcountryman closed 2 years ago

maxcountryman commented 2 years ago

This changes how sessions are provided by the middleware in order to support the ability to use session methods, like regenerate. Crucially sessions are no longer cloned and instead are stored via a handle. This handle is defined as Arc<RwLock<async_session::Session>> which allows us to clone the Arc without cloning the contained session directly.

In order to support better ergonomics we also introduce two new extractors: ReadableSession and WritableSession. These respectively enable reading and writing of sessions. Internally they acquire the lock and expose the session for manipulation.

One downside to this approach is that library consumers now need to use two separate types as opposed to using async_session::Session via Extension directly. However the API here now no longer requires Extension and enforces explicit usage of reading and writing via the public type interface.

Fixes: #5.

maxcountryman commented 2 years ago

@Ptrskay3 here's what I've put together pursuing the interior mutability option. I'd love your feedback.

maxcountryman commented 2 years ago

I'll go ahead and merge this. Thank you for your great feedback!