1004 BRaw
| 1 | use std::time::SystemTime; |
| 2 | |
| 3 | use super::RepositoryResult; |
| 4 | use crate::domain::session::{Session, SessionTokenHash}; |
| 5 | |
| 6 | /// Persistence for [`Session`]. |
| 7 | pub trait SessionRepository: Send + Sync { |
| 8 | /// Looks a session up by token hash. |
| 9 | /// |
| 10 | /// Returns whatever is stored, expired or not — expiry is the caller's decision so |
| 11 | /// that a stale row and a missing row stay distinguishable here. |
| 12 | fn find( |
| 13 | &self, |
| 14 | token_hash: &SessionTokenHash, |
| 15 | ) -> impl Future<Output = RepositoryResult<Option<Session>>> + Send; |
| 16 | |
| 17 | fn save(&self, session: &Session) -> impl Future<Output = RepositoryResult<()>> + Send; |
| 18 | |
| 19 | /// Removes a single session. Used on logout. |
| 20 | fn delete( |
| 21 | &self, |
| 22 | token_hash: &SessionTokenHash, |
| 23 | ) -> impl Future<Output = RepositoryResult<()>> + Send; |
| 24 | |
| 25 | /// Removes every session that expired before `now`, returning how many went. |
| 26 | fn delete_expired(&self, now: SystemTime) |
| 27 | -> impl Future<Output = RepositoryResult<u64>> + Send; |
| 28 | } |