Better Auth RS

Email Verification

Send and verify email addresses.

The EmailVerificationPlugin handles sending verification emails and validating tokens.

Setup

use better_auth::plugins::EmailVerificationPlugin;
use better_auth::email::ConsoleEmailProvider;

let auth = BetterAuth::new(config)
    .database(database)
    .email_provider(ConsoleEmailProvider) // Required for sending emails
    .plugin(
        EmailVerificationPlugin::new()
            .verification_token_expiry_hours(24)
            .auto_verify_new_users(false)
    )
    .build()
    .await?;

An email provider must be configured for this plugin to send emails. Without one, calling send-verification-email will return an error.

Plugin Options

OptionTypeDefaultDescription
verification_token_expiry_hoursi6424Hours before token expires
send_email_notificationsbooltrueActually send the email
require_verification_for_signinboolfalseBlock sign-in for unverified emails
auto_verify_new_usersboolfalseAuto-verify on sign-up

Send Verification Email

POST /send-verification-email
Authorization: Bearer <token>
Content-Type: application/json
{
  "email": "alice@example.com",
  "callbackURL": "https://example.com/verify"
}

Response

{
  "status": true,
  "description": "Verification email sent"
}

Verify Email

Called when the user clicks the link in the verification email.

GET /verify-email?token=<verification_token>

Response

{
  "user": {
    "id": "uuid",
    "email": "alice@example.com",
    "emailVerified": true,
    ...
  },
  "status": true
}
StatusCondition
400Token missing, expired, or invalid

Automatic Verification on Sign-Up

When auto_verify_new_users is enabled, the plugin listens to the on_user_created lifecycle event and automatically sends a verification email to newly registered users.

Email Provider

The ConsoleEmailProvider logs emails to stderr and is useful for development:

[EMAIL] To: alice@example.com | Subject: Verify your email | Body: ...

For production, implement the EmailProvider trait:

use better_auth::email::EmailProvider;

struct SmtpProvider { /* ... */ }

#[async_trait::async_trait]
impl EmailProvider for SmtpProvider {
    async fn send(
        &self, to: &str, subject: &str, html: &str, text: &str
    ) -> better_auth::error::AuthResult<()> {
        // Send via SMTP, SendGrid, etc.
        Ok(())
    }
}

On this page