use crate::{AuthContext, AuthResult, AuthSchema, AuthTransaction};
use async_trait::async_trait;
use std::sync::Arc;
#[async_trait]
pub trait SessionDeletionHook<S: AuthSchema>: Send + Sync {
async fn prepare(
&self,
session: &S::Session,
context: &AuthContext<S>,
) -> AuthResult<Option<Box<dyn SessionDeletionWork<S>>>>;
async fn prepare_in_transaction(
&self,
_session: &S::Session,
_context: &AuthContext<S>,
_transaction: &dyn AuthTransaction<S>,
) -> AuthResult<Option<Box<dyn SessionDeletionWork<S>>>> {
Err(crate::AuthError::not_implemented(
"Transactional session deletion preparation is unsupported",
))
}
}
#[async_trait]
pub trait SessionDeletionWork<S: AuthSchema>: Send + Sync {
async fn complete(&self, context: &AuthContext<S>) -> AuthResult<()>;
}
pub(crate) struct SessionDeletionHooks<S: AuthSchema>(
pub(crate) Vec<Arc<dyn SessionDeletionHook<S>>>,
);
impl<S: AuthSchema> Default for SessionDeletionHooks<S> {
fn default() -> Self {
Self(Vec::new())
}
}
impl<S: AuthSchema> Clone for SessionDeletionHooks<S> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}