[PR #6498] fix(email-otp): allow OTP to persist on validation errors #6705

Open
opened 2026-03-13 13:08:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6498
Author: @bytaesu
Created: 12/3/2025
Status: 🔄 Open

Base: canaryHead: 2025-12-04/fix/email-otp-reuse-on-validation-error


📝 Commits (6)

  • 7bd9206 fix: allow OTP reuse on validation errors
  • 06f739e test: add test cases for keepking OTP
  • 7ba5615 test: add test case for allowedAttempts guard
  • 1b979db Merge branch 'canary' into 2025-12-04/fix/email-otp-reuse-on-validation-error
  • a8f32e9 fix: delete otp when autoSignInAfterVerification is enabled
  • d530803 test: add case for when autoSignInAfterVerification is enabled

📊 Changes

2 files changed (+177 additions, -10 deletions)

View changed files

📝 packages/better-auth/src/plugins/email-otp/email-otp.test.ts (+162 -0)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+15 -10)

📄 Description

This PR addresses a Discord issue where the verificationValue is deleted immediately after validation, forcing users to restart the OTP flow if they fail to enter the correct value on the first try. OTP reuse can be controlled with allowedAttempts.


Summary by cubic

Allows email OTP to persist on validation errors so users can retry without restarting the flow. OTP is only consumed after a successful verification, sign-in, or password reset, with attempts still limited by allowedAttempts.

  • Bug Fixes
    • Move deletion of verificationValue to occur only after successful email verify, sign-in, or password reset.
    • Enforce allowedAttempts; return 403 “Too many attempts” after the limit.
    • Add tests for OTP reuse on validation failures and blocking sign-in after exceeding attempts.

Written for commit d530803f7a. 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/6498 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 12/3/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `2025-12-04/fix/email-otp-reuse-on-validation-error` --- ### 📝 Commits (6) - [`7bd9206`](https://github.com/better-auth/better-auth/commit/7bd9206a0569b0d8628cc4deeb047facd5ffaed6) fix: allow OTP reuse on validation errors - [`06f739e`](https://github.com/better-auth/better-auth/commit/06f739edcdaa67a0c20508f13921cf2836dc20d8) test: add test cases for keepking OTP - [`7ba5615`](https://github.com/better-auth/better-auth/commit/7ba561556c8115257a7c896e0830962dc6364dd9) test: add test case for allowedAttempts guard - [`1b979db`](https://github.com/better-auth/better-auth/commit/1b979dbd2b84cefbcd037d487c3bc941a26b8e1d) Merge branch 'canary' into 2025-12-04/fix/email-otp-reuse-on-validation-error - [`a8f32e9`](https://github.com/better-auth/better-auth/commit/a8f32e93d61fbe15c9674daafc0ea1392e2a52c1) fix: delete otp when autoSignInAfterVerification is enabled - [`d530803`](https://github.com/better-auth/better-auth/commit/d530803f7aa60756131cf0b143e9c1bf5bf926aa) test: add case for when autoSignInAfterVerification is enabled ### 📊 Changes **2 files changed** (+177 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/email-otp/email-otp.test.ts` (+162 -0) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+15 -10) </details> ### 📄 Description This PR addresses a [Discord issue](https://discord.com/channels/1288403910284935179/1288403910284935182/1445592492496916500) where the verificationValue is deleted immediately after validation, forcing users to restart the OTP flow if they fail to enter the correct value on the first try. OTP reuse can be controlled with `allowedAttempts`. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Allows email OTP to persist on validation errors so users can retry without restarting the flow. OTP is only consumed after a successful verification, sign-in, or password reset, with attempts still limited by allowedAttempts. - **Bug Fixes** - Move deletion of verificationValue to occur only after successful email verify, sign-in, or password reset. - Enforce allowedAttempts; return 403 “Too many attempts” after the limit. - Add tests for OTP reuse on validation failures and blocking sign-in after exceeding attempts. <sup>Written for commit d530803f7aa60756131cf0b143e9c1bf5bf926aa. 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-03-13 13:08:55 -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#6705