Email OTP

Email one-time passcodes for verification, sign-in, and password reset.

This page documents the current Ruby port behavior. Ruby uses snake_case option names and auth.api method names; HTTP paths and JSON keys keep the upstream wire shape where implemented.

Configure

config/auth.rb
require "better_auth"

auth = BetterAuth.auth(
  secret: ENV.fetch("BETTER_AUTH_SECRET"),
  base_url: ENV.fetch("BETTER_AUTH_URL", "http://localhost:3000"),
  plugins: [
    BetterAuth::Plugins.email_otp(send_verification_otp: ->(data, _ctx = nil) { Mailer.otp(data[:email], data[:otp]).deliver_now })
  ]
)

Usage

server.rb
auth.api.send_verification_otp(body: { email: "ada@example.com", type: "sign-in" })
result = auth.api.sign_in_email_otp(body: { email: "ada@example.com", otp: params[:otp] })

Routes

MethodPathRuby API method
POST/email-otp/send-verification-otpauth.api.send_verification_otp
POST/email-otp/verify-emailauth.api.verify_email_otp
POST/sign-in/email-otpauth.api.sign_in_email_otp
POST/email-otp/request-password-resetauth.api.request_password_reset_email_otp
POST/email-otp/reset-passwordauth.api.reset_password_email_otp

Options

Current Ruby options accepted by BetterAuth::Plugins.email_otp:

  • send_verification_on_sign_up
  • override_default_email_verification
  • send_verification_otp
  • store_otp
  • disable_sign_up
  • expires_in
  • allowed_attempts
  • generate_otp
  • otp_length

Support Notes

  • The examples above are based on Ruby plugin source and tests in packages/better_auth.
  • If an upstream section is not represented here, treat it as not yet documented or not yet supported by the Ruby port until the matching Ruby implementation exists.

On this page