Skip to main content

SessionStore

Struct SessionStore 

Source
pub struct SessionStore { /* private fields */ }
Expand description

A session store. In-memory by default; optionally backed by a persistent SessionBackend.

The in-memory map is always authoritative — reads don’t touch the backend. The backend receives every save/remove, making it a write-through cache. On construction via SessionStore::with_backend, the store hydrates from the backend so sessions survive restart.

Implementations§

Source§

impl SessionStore

Source

pub fn new() -> Self

Source

pub fn with_lifetime(self, lifetime_secs: u64) -> Self

Override the default session lifetime. Used by pylon-runtime’s server bootstrap to apply the manifest’s auth.session.expires_in.

Source

pub fn with_backend(backend: Box<dyn SessionBackend>) -> Self

Build a session store backed by a persistent store. Existing sessions are loaded from the backend on construction; every future mutation writes through.

Source

pub fn create(&self, user_id: String) -> Session

Create a session for a user and return it. Uses the store’s configured default_lifetime_secs (from the manifest’s auth.session.expires_in, default 30 days).

Source

pub fn get(&self, token: &str) -> Option<Session>

Look up a session by token. Returns None if the session is expired.

Source

pub fn resolve(&self, token: Option<&str>) -> AuthContext

Resolve a token to an auth context. Returns anonymous context if the token is invalid, missing, or expired.

Source

pub fn refresh(&self, old_token: &str) -> Option<Session>

Refresh a session — issues a new token, copies user/device, extends expiry. The old token is revoked. Returns the new session or None if the old token is missing/expired.

Source

pub fn list_all_unfiltered(&self) -> Vec<Session>

Every session in the store, including expired ones, with no filtering. Powers the Studio “Auth tables” view so operators can see orphaned sessions / debug stuck logins. Don’t use for app code — list_for_user is the right surface there.

Source

pub fn list_for_user(&self, user_id: &str) -> Vec<Session>

List all active sessions for a user.

Source

pub fn revoke_all_for_user(&self, user_id: &str) -> usize

Revoke all sessions for a user. Returns the count removed.

Source

pub fn sweep_expired(&self) -> usize

Sweep expired sessions. Returns the count removed.

Source

pub fn set_device(&self, token: &str, device: String) -> bool

Attach a device label to a session (typically on login from a browser).

Source

pub fn create_guest(&self) -> Session

Create a guest session with a generated anonymous ID.

Source

pub fn upgrade(&self, token: &str, real_user_id: String) -> bool

Upgrade a guest session to a real user. Replaces the user_id.

Source

pub fn set_tenant(&self, token: &str, tenant_id: Option<String>) -> bool

Switch the session’s active tenant (organization). None clears it. Callers should verify the user actually has membership in the target tenant BEFORE invoking this — the session store takes the value on trust. Returns true if the session exists, false otherwise.

Source

pub fn revoke(&self, token: &str) -> bool

Remove a session.

Trait Implementations§

Source§

impl Default for SessionStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more