[PR #3081] [CLOSED] Fix: multiple logic bugs in Email OTP plugin #21535

Closed
opened 2026-04-15 20:25:36 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3081
Author: @bytaesu
Created: 6/19/2025
Status: Closed

Base: mainHead: fix/email-otp-plugin


📝 Commits (5)

  • 16518c0 fix(email-otp): pass correct type to generateOTP in after hook
  • f232f9a fix(email-otp): return API error for unregistered users when disableSignUp is enabled
  • 91f5599 fix(email-otp): handle forget-password and sign-up-disabled flows separately
  • a827d50 refactor(email-otp): move ERROR_CODES to separate file
  • b617180 test(email-otp): add bug fix test codes

📊 Changes

3 files changed (+249 additions, -14 deletions)

View changed files

packages/better-auth/src/plugins/email-otp/email-otp-error.ts (+8 -0)
packages/better-auth/src/plugins/email-otp/email-otp-fix.test.ts (+228 -0)
📝 packages/better-auth/src/plugins/email-otp/index.ts (+13 -14)

📄 Description

This PR is related to Email OTP plugin.

[Fix]

  • Ensure generateOTP receives the correct type ("email-verification") during sign-up when sendVerificationOnSignUp is enabled.
  • Return a proper API error (USER_NOT_FOUND) when disableSignUp is true and a verification request is made for a non-existent user.
  • Return a generic success response for non-existent users when type is "forget-password" (for security reasons), while "email-verification" properly returns an error.

[Refactor]

  • Extracted ERROR_CODES from index.ts to email-otp-error.ts in the same folder.

[Test]

  • Add test code about this PR

Before

behavior

a b

After

test

All tests have been written and run locally to confirm the fixes. Please take a look and let me know if there’s anything that needs improvement.

I need the Email OTP plugin, so I’d really appreciate your review.


🔄 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/3081 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 6/19/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/email-otp-plugin` --- ### 📝 Commits (5) - [`16518c0`](https://github.com/better-auth/better-auth/commit/16518c09af2f1cabfe874814260f54e6f396897b) fix(email-otp): pass correct type to generateOTP in after hook - [`f232f9a`](https://github.com/better-auth/better-auth/commit/f232f9a796a19ef0af2109da64f84fa95d0e9581) fix(email-otp): return API error for unregistered users when disableSignUp is enabled - [`91f5599`](https://github.com/better-auth/better-auth/commit/91f5599909234a577aee5335dbcaefc03b3cc92e) fix(email-otp): handle forget-password and sign-up-disabled flows separately - [`a827d50`](https://github.com/better-auth/better-auth/commit/a827d50bcf0ed88cf4314abfc9344029bb41c586) refactor(email-otp): move ERROR_CODES to separate file - [`b617180`](https://github.com/better-auth/better-auth/commit/b617180c6aa643426373699beaa082462a11d2be) test(email-otp): add bug fix test codes ### 📊 Changes **3 files changed** (+249 additions, -14 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/plugins/email-otp/email-otp-error.ts` (+8 -0) ➕ `packages/better-auth/src/plugins/email-otp/email-otp-fix.test.ts` (+228 -0) 📝 `packages/better-auth/src/plugins/email-otp/index.ts` (+13 -14) </details> ### 📄 Description This PR is related to Email OTP plugin. [Fix] - Ensure generateOTP receives the correct type ("email-verification") during sign-up when sendVerificationOnSignUp is enabled. - Return a proper API error (USER_NOT_FOUND) when disableSignUp is true and a verification request is made for a non-existent user. - Return a generic success response for non-existent users when type is "forget-password" (for security reasons), while "email-verification" properly returns an error. [Refactor] - Extracted ERROR_CODES from `index.ts` to `email-otp-error.ts` in the same folder. [Test] - Add test code about this PR --- ### **Before** ![behavior](https://github.com/user-attachments/assets/c7b86698-7f73-4232-a6be-77f510afe964) <img width="1555" alt="a" src="https://github.com/user-attachments/assets/c4370b8c-bf4c-436b-841a-3f0457726d16" /> <img width="1555" alt="b" src="https://github.com/user-attachments/assets/2d3a319c-3959-4440-b407-83e91cd1dca6" /> ### **After** <img width="708" alt="test" src="https://github.com/user-attachments/assets/4487813c-5b2e-4ab7-9775-ba9e1ac0f0ec" /> All tests have been written and run locally to confirm the fixes. Please take a look and let me know if there’s anything that needs improvement. I need the Email OTP plugin, so I’d really appreciate your review. --- <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-15 20:25:36 -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#21535