pub trait SessionStore: Send + Sync {
// Required methods
fn store<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 Session,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<Option<Session>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AuthResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Port: Session storage
Implement this trait to use different session backends (database, Redis, in-memory, etc.)
§Example
use lmrc_auth::{SessionStore, Session, AuthResult};
use async_trait::async_trait;
struct RedisSessionStore {
// Redis connection pool
}
#[async_trait]
impl SessionStore for RedisSessionStore {
async fn store(&self, session: &Session) -> AuthResult<()> {
// Store in Redis
todo!()
}
async fn get(&self, token: &str) -> AuthResult<Option<Session>> {
// Retrieve from Redis
todo!()
}
async fn delete(&self, token: &str) -> AuthResult<()> {
// Delete from Redis
todo!()
}
async fn cleanup_expired(&self) -> AuthResult<usize> {
// Clean up expired sessions
todo!()
}
}Required Methods§
Sourcefn store<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 Session,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn store<'life0, 'life1, 'async_trait>(
&'life0 self,
session: &'life1 Session,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Store a session
Persists the session to the backing storage.
Sourcefn get<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<Option<Session>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<Option<Session>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Retrieve a session by token
Returns None if the session doesn’t exist.
Sourcefn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
token: &'life1 str,
) -> Pin<Box<dyn Future<Output = AuthResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Delete a session
Removes the session from storage.
Sourcefn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AuthResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn cleanup_expired<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = AuthResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clean up expired sessions
Returns the number of sessions deleted.