[PR #5926] [MERGED] feat(phone-number): allow custom verifyOTP implementation #31930

Closed
opened 2026-04-17 22:48:25 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5926
Author: @bytaesu
Created: 11/12/2025
Status: Merged
Merged: 11/16/2025
Merged by: @Bekacru

Base: canaryHead: 2025-11-12/feat/custom-verify-otp


📝 Commits (10+)

  • 05a804e refactor: plugin file structure
  • d716176 feat: allow custom verifyOTP implementation for phone-number plugin
  • ad568df test: proper getTestInstance usage
  • 1915b65 docs: update phone-number docs content
  • 00619dc Merge branch 'canary' into 2025-11-12/feat/custom-verify-otp
  • 2ffb866 fix: ctx.request to ctx
  • 0778381 refactor: cleanup type
  • ef399d4 refactor: cleanup api errors
  • e80397a fix: lint
  • 04e5df7 fix: clean up verification value

📊 Changes

6 files changed (+569 additions, -325 deletions)

View changed files

📝 docs/content/docs/plugins/phone-number.mdx (+65 -13)
📝 packages/better-auth/src/plugins/phone-number/error-codes.ts (+5 -1)
📝 packages/better-auth/src/plugins/phone-number/index.ts (+80 -178)
📝 packages/better-auth/src/plugins/phone-number/phone-number.test.ts (+267 -133)
packages/better-auth/src/plugins/phone-number/schema.ts (+21 -0)
packages/better-auth/src/plugins/phone-number/types.ts (+131 -0)

📄 Description

This PR is based on #1576 by @zain

Tasks

  • Refactor phone number plugin folder
  • Add verifyOTP feature
  • Add unit tests for new API
  • Refactor existing test codes to use proper test instances
  • Update documentation

Closes https://github.com/better-auth/better-auth/issues/1159


Summary by cubic

Adds a custom verifyOTP option to the phone-number plugin so apps can use external OTP verification providers while keeping the existing default flow unchanged. Also refactors the plugin structure and updates tests.

  • New Features

    • Added options.verifyOTP to override internal OTP checks; used in verify and updatePhoneNumber flows.
    • Default OTP logic (expiry and attempt limits) still applies when verifyOTP is not provided.
    • Standardized error exposure via $ERROR_CODES backed by PHONE_NUMBER_ERROR_CODES.
  • Refactors

    • Moved schema to schema.ts and types to types.ts; trimmed index.ts.
    • Renamed ERROR_CODES to PHONE_NUMBER_ERROR_CODES and updated imports.
    • Updated tests to use getTestInstance and added coverage for custom verifyOTP.

Written for commit 04e5df705f. Summary will update automatically 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/5926 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 11/12/2025 **Status:** ✅ Merged **Merged:** 11/16/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `2025-11-12/feat/custom-verify-otp` --- ### 📝 Commits (10+) - [`05a804e`](https://github.com/better-auth/better-auth/commit/05a804e073734831fdbd37bf5e666aaa4c1cf15e) refactor: plugin file structure - [`d716176`](https://github.com/better-auth/better-auth/commit/d7161769140821b4cdc05050a1eba43fac10c059) feat: allow custom verifyOTP implementation for phone-number plugin - [`ad568df`](https://github.com/better-auth/better-auth/commit/ad568df05c81b88b9068e358b3fe0cfc8e72fb27) test: proper getTestInstance usage - [`1915b65`](https://github.com/better-auth/better-auth/commit/1915b65bf844942eedee03db8978b0436c2b1900) docs: update phone-number docs content - [`00619dc`](https://github.com/better-auth/better-auth/commit/00619dca220db5a45ddcbc4d3701080010b52ef0) Merge branch 'canary' into 2025-11-12/feat/custom-verify-otp - [`2ffb866`](https://github.com/better-auth/better-auth/commit/2ffb8669c8defe170eb83d61256c1c7df00f60d0) fix: ctx.request to ctx - [`0778381`](https://github.com/better-auth/better-auth/commit/07783819e562c156da99aeb39269b89a702ed4b3) refactor: cleanup type - [`ef399d4`](https://github.com/better-auth/better-auth/commit/ef399d4c26022fbcf10f5fbc3c3ec43bee15bde6) refactor: cleanup api errors - [`e80397a`](https://github.com/better-auth/better-auth/commit/e80397a434baa7f3608ae5e1b991d2c19a786457) fix: lint - [`04e5df7`](https://github.com/better-auth/better-auth/commit/04e5df705fb846f7be247931333f924b1eaea32c) fix: clean up verification value ### 📊 Changes **6 files changed** (+569 additions, -325 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/plugins/phone-number.mdx` (+65 -13) 📝 `packages/better-auth/src/plugins/phone-number/error-codes.ts` (+5 -1) 📝 `packages/better-auth/src/plugins/phone-number/index.ts` (+80 -178) 📝 `packages/better-auth/src/plugins/phone-number/phone-number.test.ts` (+267 -133) ➕ `packages/better-auth/src/plugins/phone-number/schema.ts` (+21 -0) ➕ `packages/better-auth/src/plugins/phone-number/types.ts` (+131 -0) </details> ### 📄 Description This PR is based on #1576 by @zain ### Tasks - [x] Refactor phone number plugin folder - [x] Add verifyOTP feature - [x] Add unit tests for new API - [x] Refactor existing test codes to use proper test instances - [x] Update documentation Closes https://github.com/better-auth/better-auth/issues/1159 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a custom verifyOTP option to the phone-number plugin so apps can use external OTP verification providers while keeping the existing default flow unchanged. Also refactors the plugin structure and updates tests. - **New Features** - Added options.verifyOTP to override internal OTP checks; used in verify and updatePhoneNumber flows. - Default OTP logic (expiry and attempt limits) still applies when verifyOTP is not provided. - Standardized error exposure via $ERROR_CODES backed by PHONE_NUMBER_ERROR_CODES. - **Refactors** - Moved schema to schema.ts and types to types.ts; trimmed index.ts. - Renamed ERROR_CODES to PHONE_NUMBER_ERROR_CODES and updated imports. - Updated tests to use getTestInstance and added coverage for custom verifyOTP. <sup>Written for commit 04e5df705fb846f7be247931333f924b1eaea32c. Summary will update automatically 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-04-17 22:48:25 -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#31930