pub struct SessionLayer { /* private fields */ }Expand description
Session middleware over a SessionStore.
Cookie load/save stays here. App logic (hydrate user, ACL, …) goes in SessionLayer::hook.
Implementations§
Source§impl SessionLayer
impl SessionLayer
Sourcepub fn new(kv: Arc<dyn KvStore>) -> Self
pub fn new(kv: Arc<dyn KvStore>) -> Self
Wrap a KvStore (typically namespace(store, "sess")) in KvSessionStore.
Sourcepub fn from_store(store: Arc<dyn SessionStore>) -> Self
pub fn from_store(store: Arc<dyn SessionStore>) -> Self
Use an arbitrary SessionStore (e.g. [SqlSessionStore]).
Sourcepub fn from_app_store(app: &App) -> Self
pub fn from_app_store(app: &App) -> Self
Sessions on an installed sova_store::AppStore (namespaced sess).
pub fn secure(self, secure: bool) -> Self
pub fn http_only(self, on: bool) -> Self
pub fn same_site(self, same_site: SameSite) -> Self
pub fn path(self, path: impl Into<String>) -> Self
pub fn ttl(self, ttl: Duration) -> Self
Sourcepub fn save_uninitialized(self, on: bool) -> Self
pub fn save_uninitialized(self, on: bool) -> Self
Persist empty new sessions (Express default false).
Sourcepub fn hook<F, Fut>(self, f: F) -> Self
pub fn hook<F, Fut>(self, f: F) -> Self
After cookie session is loaded (and set on req), run app logic.
Clone Arcs from req before async move. Return the (possibly mutated) request:
ⓘ
SessionLayer::new(store).hook(|sess, mut req| async move {
if let Some(id) = sess.get("user_id") {
let db = req.state::<Db>().clone();
if let Some(u) = find_user(&db, &id).await? {
req.set(u);
}
}
Ok(req)
})Trait Implementations§
Source§impl Plugin for SessionLayer
impl Plugin for SessionLayer
Source§fn id(&self) -> &'static str
fn id(&self) -> &'static str
Stable plugin identifier used for dependency checks and
crate::App::has_plugin. Read moreSource§fn meta(&self) -> PluginMeta
fn meta(&self) -> PluginMeta
Display name, description, and declared
PluginMeta::sdk version.Auto Trait Implementations§
impl !RefUnwindSafe for SessionLayer
impl !UnwindSafe for SessionLayer
impl Freeze for SessionLayer
impl Send for SessionLayer
impl Sync for SessionLayer
impl Unpin for SessionLayer
impl UnsafeUnpin for SessionLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more