[PR #7267] [CLOSED] feat(phone-number): align API with email-otp plugin for consistency #7185

Closed
opened 2026-03-13 13:27:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7267
Author: @meetgoti07
Created: 1/11/2026
Status: Closed

Base: canaryHead: fix/align_otp_plugins


📝 Commits (3)

  • 36cc6db feat(phone-number): align API with email-otp plugin for consistency
  • 9c2629d fix(phone-number): fix security and behavior issues
  • 0a6507f Merge branch 'canary' into fix/align_otp_plugins

📊 Changes

6 files changed (+1916 additions, -92 deletions)

View changed files

📝 packages/better-auth/src/plugins/phone-number/client.ts (+3 -1)
📝 packages/better-auth/src/plugins/phone-number/index.ts (+50 -2)
📝 packages/better-auth/src/plugins/phone-number/phone-number.test.ts (+854 -7)
📝 packages/better-auth/src/plugins/phone-number/routes.ts (+983 -80)
📝 packages/better-auth/src/plugins/phone-number/types.ts (+19 -2)
packages/better-auth/src/plugins/phone-number/utils.ts (+7 -0)

📄 Description

Summary

This PR refactors the Phone Number plugin to align its API design, features, and user experience with the existing Email OTP plugin, ensuring consistency and better developer experience across authentication methods.
Fixes https://github.com/better-auth/better-auth/issues/6943

Changes

New API Methods

  • sendVerificationOtp({ phoneNumber, type }) - Send OTP with type context

    • Types: "phone-number-verification" | "sign-in" | "forget-password"
    • Replaces sendOtp() (deprecated)
  • checkVerificationOtp({ phoneNumber, type, otp }) - Validate OTP without performing action

    • Enables multi-step flows (e.g., 3-step password reset)
    • Does not require user existence (prevents enumeration)
    • Does not delete OTP on check
  • signInPhoneNumberOtp({ phoneNumber, otp }) - Dedicated passwordless sign-in

    • Always creates session
    • Supports disableSignUp option
    • Replaces implicit sign-in behavior of old verify()
  • verifyPhoneNumber({ phoneNumber, otp, disableSession?, updatePhoneNumber? }) - Phone verification

    • Does not create session by default
    • Clear separation from sign-in flow

Improvements

  • Type Parameter: OTPs now have context (type) to distinguish between verification, sign-in, and password reset flows
  • Parameter Naming: Standardized from code to otp for consistency
  • 3-Step Password Reset: Enables early OTP validation before password entry
  • User Enumeration Prevention: checkVerificationOtp works without requiring user existence
  • Backward Compatibility: Old methods (sendOtp, verify) are deprecated but still functional

Technical Details

  • Added PhoneNumberOTPType union type
  • Updated sendOTP callback to include optional type parameter
  • Implemented verifyOTPValue helper for centralized OTP validation

Testing

  • 42 tests passing
  • Comprehensive coverage of new API methods
  • Backward compatibility tests

Summary by cubic

Aligns the phone-number plugin API with the email-otp plugin for consistency. Adds type-based OTP endpoints, clarifies sign-in vs verification flows, and deprecates old methods to improve security and DX.

  • New Features

    • Added sendVerificationOtp(type), checkVerificationOtp, signInPhoneNumberOtp, and verifyPhoneNumber (no session by default; set disableSession: false to create one).
    • OTPs now carry a type: "phone-number-verification", "sign-in", or "forget-password".
    • Standardized parameter to otp for consistency with email-otp.
    • 3-step password reset with early OTP check and user enumeration protection.
    • Added rate limits and a shared OTP validation helper; fixed attempt tracking for custom verifyOTP; updated client route matching.
  • Migration

    • Replace sendOtp with sendVerificationOtp({ type: "phone-number-verification" }).
    • Use signInPhoneNumberOtp for passwordless sign-in; use verifyPhoneNumber for verification-only (set disableSession: false to create a session).
    • resetPassword now prefers password (newPassword still supported).
    • Update callbacks: sendOTP({ phoneNumber, code, type? }) and sendPasswordResetOTP({ phoneNumber, code, type: "forget-password" }).
    • Adopt PhoneNumberOTPType and optional disableSignUp to prevent auto sign-up.

Written for commit 0a6507fd49. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7267 **Author:** [@meetgoti07](https://github.com/meetgoti07) **Created:** 1/11/2026 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/align_otp_plugins` --- ### 📝 Commits (3) - [`36cc6db`](https://github.com/better-auth/better-auth/commit/36cc6dbb7f82657b6eee6b6b48f2a22dfecf95a1) feat(phone-number): align API with email-otp plugin for consistency - [`9c2629d`](https://github.com/better-auth/better-auth/commit/9c2629dd43e778c6727387c58d206a69b7d219f3) fix(phone-number): fix security and behavior issues - [`0a6507f`](https://github.com/better-auth/better-auth/commit/0a6507fd497cbec6ea31f5beefc07a274ba15e3d) Merge branch 'canary' into fix/align_otp_plugins ### 📊 Changes **6 files changed** (+1916 additions, -92 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/phone-number/client.ts` (+3 -1) 📝 `packages/better-auth/src/plugins/phone-number/index.ts` (+50 -2) 📝 `packages/better-auth/src/plugins/phone-number/phone-number.test.ts` (+854 -7) 📝 `packages/better-auth/src/plugins/phone-number/routes.ts` (+983 -80) 📝 `packages/better-auth/src/plugins/phone-number/types.ts` (+19 -2) ➕ `packages/better-auth/src/plugins/phone-number/utils.ts` (+7 -0) </details> ### 📄 Description ## Summary This PR refactors the Phone Number plugin to align its API design, features, and user experience with the existing Email OTP plugin, ensuring consistency and better developer experience across authentication methods. Fixes https://github.com/better-auth/better-auth/issues/6943 ## Changes ### New API Methods - **`sendVerificationOtp({ phoneNumber, type })`** - Send OTP with type context - Types: `"phone-number-verification" | "sign-in" | "forget-password"` - Replaces `sendOtp()` (deprecated) - **`checkVerificationOtp({ phoneNumber, type, otp })`** - Validate OTP without performing action - Enables multi-step flows (e.g., 3-step password reset) - Does not require user existence (prevents enumeration) - Does not delete OTP on check - **`signInPhoneNumberOtp({ phoneNumber, otp })`** - Dedicated passwordless sign-in - Always creates session - Supports `disableSignUp` option - Replaces implicit sign-in behavior of old `verify()` - **`verifyPhoneNumber({ phoneNumber, otp, disableSession?, updatePhoneNumber? })`** - Phone verification - Does not create session by default - Clear separation from sign-in flow ### Improvements - **Type Parameter**: OTPs now have context (`type`) to distinguish between verification, sign-in, and password reset flows - **Parameter Naming**: Standardized from `code` to `otp` for consistency - **3-Step Password Reset**: Enables early OTP validation before password entry - **User Enumeration Prevention**: `checkVerificationOtp` works without requiring user existence - **Backward Compatibility**: Old methods (`sendOtp`, `verify`) are deprecated but still functional ### Technical Details - Added `PhoneNumberOTPType` union type - Updated `sendOTP` callback to include optional `type` parameter - Implemented `verifyOTPValue` helper for centralized OTP validation ## Testing - [x] 42 tests passing - [x] Comprehensive coverage of new API methods - [x] Backward compatibility tests <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Aligns the phone-number plugin API with the email-otp plugin for consistency. Adds type-based OTP endpoints, clarifies sign-in vs verification flows, and deprecates old methods to improve security and DX. - **New Features** - Added sendVerificationOtp(type), checkVerificationOtp, signInPhoneNumberOtp, and verifyPhoneNumber (no session by default; set disableSession: false to create one). - OTPs now carry a type: "phone-number-verification", "sign-in", or "forget-password". - Standardized parameter to otp for consistency with email-otp. - 3-step password reset with early OTP check and user enumeration protection. - Added rate limits and a shared OTP validation helper; fixed attempt tracking for custom verifyOTP; updated client route matching. - **Migration** - Replace sendOtp with sendVerificationOtp({ type: "phone-number-verification" }). - Use signInPhoneNumberOtp for passwordless sign-in; use verifyPhoneNumber for verification-only (set disableSession: false to create a session). - resetPassword now prefers password (newPassword still supported). - Update callbacks: sendOTP({ phoneNumber, code, type? }) and sendPasswordResetOTP({ phoneNumber, code, type: "forget-password" }). - Adopt PhoneNumberOTPType and optional disableSignUp to prevent auto sign-up. <sup>Written for commit 0a6507fd497cbec6ea31f5beefc07a274ba15e3d. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:27:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7185