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
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
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
| Method | Path | Ruby API method |
|---|---|---|
POST | /email-otp/send-verification-otp | auth.api.send_verification_otp |
POST | /email-otp/verify-email | auth.api.verify_email_otp |
POST | /sign-in/email-otp | auth.api.sign_in_email_otp |
POST | /email-otp/request-password-reset | auth.api.request_password_reset_email_otp |
POST | /email-otp/reset-password | auth.api.reset_password_email_otp |
Options
Current Ruby options accepted by BetterAuth::Plugins.email_otp:
send_verification_on_sign_upoverride_default_email_verificationsend_verification_otpstore_otpdisable_sign_upexpires_inallowed_attemptsgenerate_otpotp_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.