Expand description
Session manage system for axum.
§OverView
Sessions are managed using cookies, and session-related operations
(issuing a session ID, checking sessions, deleting sessions) can be implemented with SessionManageTrait,
and session checking is automatically performed at all endpoints by axum::routing::Router::layer
and tower::Service
as middleware.
At each endpoint, whether a user has a session can be received as UserData via axum::extension::Extention,
and data about the user who has a session is also included there.
§feature
The important parts of this crate are the SessionManage
trait, the UserData
struct, and the UserState
enum.
§usage
§implment session manage system as amiddleware
- define session pool
- implement
SessionManage
trait for session pool you defined step 1 - Create
SessionManagerLayer
struct by usingSessionManagerLayer::new()
method - insert
SessionManagerLayer
struct you defined step 3, into axum::route::layer
§get data in your handler
- use
Extention<UserData<T>>
- get data in
UserData
struct tuple field - matching
UserState
HaveSession, NoCookie, NoSession case
Please see example for more details.
Re-exports§
pub use layer::SessionManagerLayer;
pub use manager::SessionManage;
pub use manager::UserData;
pub use manager::UserState;