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
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
auth.api.send_phone_number_otp(body: { phoneNumber: "+15551234567" })
result = auth.api.verify_phone_number(body: { phoneNumber: "+15551234567", code: params[:code] })Routes
| Method | Path | Ruby API method |
|---|---|---|
POST | /phone-number/send-otp | auth.api.send_phone_number_otp |
POST | /phone-number/verify | auth.api.verify_phone_number |
POST | /sign-in/phone-number | auth.api.sign_in_phone_number |
POST | /phone-number/request-password-reset | auth.api.request_password_reset_phone_number |
POST | /phone-number/reset-password | auth.api.reset_password_phone_number |
Options
Current Ruby options accepted by BetterAuth::Plugins.phone_number:
require_verificationsend_otpsign_up_on_verificationcallback_on_verificationsend_password_reset_otpverify_otpallowed_attemptsexpires_inphone_number_validatorotp_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.