pub struct Session {
pub token: String,
pub user_id: String,
pub expires_at: u64,
pub device: Option<String>,
pub created_at: u64,
pub tenant_id: Option<String>,
}Expand description
A session token and its associated user.
Fields§
§token: String§user_id: String§expires_at: u64Unix epoch seconds at which this session expires. 0 = never.
device: Option<String>Optional user-agent / device tag recorded at session creation.
created_at: u64Unix epoch seconds when the session was created.
tenant_id: Option<String>Active tenant id (selected organization). Set via
/api/auth/select-org. Flows into AuthContext.tenant_id which
powers row-scoped policies like data.orgId == auth.tenantId.
Implementations§
Source§impl Session
impl Session
Sourcepub const DEFAULT_LIFETIME_SECS: u64
pub const DEFAULT_LIFETIME_SECS: u64
Default session lifetime: 30 days.
Sourcepub fn new(user_id: String) -> Self
pub fn new(user_id: String) -> Self
Create a new session with a generated token and default 30-day expiry.
Sourcepub fn with_lifetime(user_id: String, lifetime_secs: u64) -> Self
pub fn with_lifetime(user_id: String, lifetime_secs: u64) -> Self
Create a session with a specific lifetime.
Sourcepub fn to_auth_context(&self) -> AuthContext
pub fn to_auth_context(&self) -> AuthContext
Convert this session to an auth context, carrying the selected
tenant so row-scoped policies see auth.tenantId.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Returns true if the session has passed its expires_at time.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Session
impl<'de> Deserialize<'de> for Session
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Session
impl StructuralPartialEq for Session
Auto Trait Implementations§
impl Freeze for Session
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
impl UnwindSafe for Session
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