pub struct Session {
pub token_hash: Vec<u8>,
pub user_id: i64,
pub created_at: i64,
pub expires_at: i64,
}Expand description
A row in the sessions table, representing an active authenticated session.
Sessions are identified by an opaque token (a UUID) that the client stores locally. The server never stores the raw token — only its BLAKE3 hash. This means even if the database is compromised, an attacker cannot reconstruct the original tokens.
Session lifetime is 30 days from creation. Expired sessions are lazily revoked
the next time the token is presented to the auth_guard middleware.
Fields§
§token_hash: Vec<u8>§user_id: i64§created_at: i64§expires_at: i64Implementations§
Source§impl Session
impl Session
Sourcepub async fn create(pool: &SqlitePool, user_id: i64) -> Result<String>
pub async fn create(pool: &SqlitePool, user_id: i64) -> Result<String>
Creates a new entry in Sessions entity then returns a hashed token as String
§Errors
- Fails with [
sqlx::sqlite::SqliteQueryResult] if an error occurs interacting with sqlite database. - Returns an error if system time is set earlier than
UNIX_EPOCH.
Trait Implementations§
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more