pub trait SessionStore: Send + Sync {
// Required methods
fn create_session<'life0, 'life1, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
expires_at: u64,
) -> Pin<Box<dyn Future<Output = Result<TokenPair>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get_session<'life0, 'life1, 'async_trait>(
&'life0 self,
refresh_token_hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<SessionData>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn revoke_session<'life0, 'life1, 'async_trait>(
&'life0 self,
refresh_token_hash: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn revoke_all_sessions<'life0, 'life1, 'async_trait>(
&'life0 self,
user_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
}Expand description
SessionStore trait - implement this for your storage backend
§Examples
Implement for PostgreSQL:
ⓘ
pub struct PostgresSessionStore {
pool: PgPool,
}
#[async_trait]
impl SessionStore for PostgresSessionStore {
async fn create_session(...) -> Result<TokenPair> { ... }
// ... other methods
}Implement for Redis:
ⓘ
pub struct RedisSessionStore {
client: redis::Client,
}
#[async_trait]
impl SessionStore for RedisSessionStore {
async fn create_session(...) -> Result<TokenPair> { ... }
// ... other methods
}