Skip to main content

waveless_commons/auth/
session.rs

1// Waveless
2// Copyright (C) 2026 Oscar Alvarez Gonzalez
3
4use crate::*;
5
6use super::*;
7
8/// Trait implemented for every session's storage backend.
9#[typetag::serde]
10#[async_trait]
11pub trait AnySessionMethod: AnyExt + DatabaseConsumer {
12    fn max_age(&self) -> Option<usize> {
13        None
14    }
15
16    /// Get whether a user is authenticated by the given session token.
17    async fn check(&self, db_conns: DbConns, token: CompactString) -> Result<Option<UserId>>;
18
19    /// Create a new session for the given user.
20    async fn new(&self, db_conns: DbConns, user_id: UserId) -> Result<CompactString>;
21
22    /// Invalidate all session's of the given user.
23    async fn invalidate(
24        &self,
25        db_conns: DbConns,
26        user_id: UserId,
27        token: Option<CompactString>,
28    ) -> Result<()>;
29
30    /// Remove all the expired sessions.
31    async fn remove_expired(&self, db_conn: Arc<dyn AnyDatabaseConnection>) -> Result<()>;
32}