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:
// Requires: sqlx PgPool and live PostgreSQL connection.
use async_trait::async_trait;
use fraiseql_auth::session::{SessionStore, SessionData, TokenPair};
use fraiseql_auth::error::Result;
pub struct PostgresSessionStore {
// pool: sqlx::PgPool,
}
#[async_trait]
impl SessionStore for PostgresSessionStore {
async fn create_session(&self, _user_id: &str, _expires_at: u64) -> Result<TokenPair> {
panic!("example stub")
}
async fn get_session(&self, _refresh_token_hash: &str) -> Result<SessionData> {
panic!("example stub")
}
async fn revoke_session(&self, _refresh_token_hash: &str) -> Result<()> {
panic!("example stub")
}
async fn revoke_all_sessions(&self, _user_id: &str) -> Result<()> {
panic!("example stub")
}
}Implement for Redis:
// Requires: redis crate and live Redis connection.
use async_trait::async_trait;
use fraiseql_auth::session::{SessionStore, SessionData, TokenPair};
use fraiseql_auth::error::Result;
pub struct RedisSessionStore {
// client: redis::Client,
}
#[async_trait]
impl SessionStore for RedisSessionStore {
async fn create_session(&self, _user_id: &str, _expires_at: u64) -> Result<TokenPair> {
panic!("example stub")
}
async fn get_session(&self, _refresh_token_hash: &str) -> Result<SessionData> {
panic!("example stub")
}
async fn revoke_session(&self, _refresh_token_hash: &str) -> Result<()> {
panic!("example stub")
}
async fn revoke_all_sessions(&self, _user_id: &str) -> Result<()> {
panic!("example stub")
}
}