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.
Boundary is inclusive (>=) to match the rest of the codebase
(magic_codes.expires_at <= now, oauth_state.expires_at <= now).