pub mod types;
#[cfg(feature = "backend-postgres")]
pub mod postgres;
#[cfg(feature = "backend-sqlite")]
pub mod sqlite;
pub use types::*;
#[cfg(feature = "backend-postgres")]
pub use postgres::{PostgresSessionStore, PostgresUserStore};
#[cfg(feature = "backend-sqlite")]
pub use sqlite::{SqliteSessionStore, SqliteUserStore};
#[async_trait::async_trait]
pub trait UserStore: Send + Sync + 'static {
async fn create_user(&self, user: &User) -> anyhow::Result<()>;
async fn get_user_by_id(&self, id: &str) -> anyhow::Result<Option<User>>;
async fn get_user_by_email(&self, email: &str) -> anyhow::Result<Option<User>>;
async fn update_user(&self, user: &User) -> anyhow::Result<()>;
async fn list_users(
&self,
limit: i64,
offset: i64,
search: Option<&str>,
) -> anyhow::Result<Vec<User>>;
async fn count_users(&self, search: Option<&str>) -> anyhow::Result<i64>;
async fn delete_user(&self, id: &str) -> anyhow::Result<bool>;
async fn set_password_hash(&self, user_id: &str, hash: &str) -> anyhow::Result<()>;
async fn get_password_hash(&self, user_id: &str) -> anyhow::Result<Option<String>>;
async fn list_passkeys(&self, user_id: &str) -> anyhow::Result<Vec<PasskeyCred>>;
async fn add_passkey(&self, user_id: &str, cred: &PasskeyCred) -> anyhow::Result<()>;
async fn remove_passkey(&self, credential_id: &[u8]) -> anyhow::Result<bool>;
async fn link_upstream(
&self,
user_id: &str,
provider: &str,
subject: &str,
) -> anyhow::Result<()>;
async fn get_user_by_upstream(
&self,
provider: &str,
subject: &str,
) -> anyhow::Result<Option<User>>;
async fn list_upstream_for_user(&self, user_id: &str) -> anyhow::Result<Vec<(String, String)>>;
}
#[async_trait::async_trait]
pub trait SessionStore: Send + Sync + 'static {
async fn create(&self, session: &Session) -> anyhow::Result<()>;
async fn get(&self, id: &str) -> anyhow::Result<Option<Session>>;
async fn delete(&self, id: &str) -> anyhow::Result<bool>;
async fn list_for_user(&self, user_id: &str) -> anyhow::Result<Vec<Session>>;
async fn delete_for_user(&self, user_id: &str) -> anyhow::Result<u64>;
async fn purge_expired(&self, now: f64) -> anyhow::Result<u64>;
async fn list_all(
&self,
limit: i64,
offset: i64,
user_filter: Option<&str>,
) -> anyhow::Result<Vec<Session>>;
async fn count_all(&self, user_filter: Option<&str>) -> anyhow::Result<i64>;
}