better_auth_api/plugins/email_verification/
callbacks.rs1use super::EmailVerificationPlugin;
2use crate::plugins::endpoint_context::{EndpointContext, WithCallbacks};
3use better_auth_core::{
4 AuthPlugin, AuthResult, AuthSchema, background::BackgroundFuture, wire::UserView,
5};
6use std::sync::Arc;
7
8#[derive(Clone)]
10pub struct VerificationEmail {
11 pub user: UserView,
13 pub url: String,
15 pub token: String,
17}
18type Sender<S> = dyn Fn(&VerificationEmail, &EndpointContext<'_, S>) -> AuthResult<Option<BackgroundFuture>>
19 + Send
20 + Sync;
21
22pub struct EmailVerificationCallbacks<S: AuthSchema> {
24 pub(super) sender: Arc<Sender<S>>,
25}
26impl<S: AuthSchema> EmailVerificationCallbacks<S> {
27 pub fn send(
30 callback: impl Fn(
31 &VerificationEmail,
32 &EndpointContext<'_, S>,
33 ) -> AuthResult<Option<BackgroundFuture>>
34 + Send
35 + Sync
36 + 'static,
37 ) -> Self {
38 Self {
39 sender: Arc::new(callback),
40 }
41 }
42}
43impl EmailVerificationPlugin {
44 pub fn callbacks<S: AuthSchema>(
46 self,
47 callbacks: EmailVerificationCallbacks<S>,
48 ) -> impl AuthPlugin<S> {
49 WithCallbacks {
50 plugin: self,
51 callbacks: Arc::new(callbacks),
52 }
53 }
54}