Phone Number

Phone 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.phone_number(send_otp: ->(data, _ctx = nil) { SmsClient.send_code(data[:phone_number], data[:code]) })
  ]
)

Usage

server.rb
auth.api.send_phone_number_otp(body: { phoneNumber: "+15551234567" })
result = auth.api.verify_phone_number(body: { phoneNumber: "+15551234567", code: params[:code] })

Routes

MethodPathRuby API method
POST/phone-number/send-otpauth.api.send_phone_number_otp
POST/phone-number/verifyauth.api.verify_phone_number
POST/sign-in/phone-numberauth.api.sign_in_phone_number
POST/phone-number/request-password-resetauth.api.request_password_reset_phone_number
POST/phone-number/reset-passwordauth.api.reset_password_phone_number

Options

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

  • require_verification
  • send_otp
  • sign_up_on_verification
  • callback_on_verification
  • send_password_reset_otp
  • verify_otp
  • allowed_attempts
  • expires_in
  • phone_number_validator
  • 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