[PR #7704] fix(email-otp): throw USER_NOT_FOUND when email records do not exist (#7696) #24403

Open
opened 2026-04-15 22:21:19 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7704
Author: @biniam0
Created: 1/30/2026
Status: 🔄 Open

Base: mainHead: fix/email-otp-user-not-found


📝 Commits (1)

  • 05e658e fix(email-otp): throw USER_NOT_FOUND when sign-up is disabled

📊 Changes

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

View changed files

📝 packages/better-auth/src/plugins/email-otp/email-otp.test.ts (+4 -5)
📝 packages/better-auth/src/plugins/email-otp/routes.ts (+6 -1)

📄 Description

PR description:

  1. What & why

    • When the Email OTP plugin was used with disableSignUp: true, calling sendVerificationOTP with type: "sign-in" for an unregistered email returned 200 with { success: true } instead of an error. That made it impossible for clients to tell “user not found” from “OTP sent,” and broke flows that rely on showing a “no account” message or redirecting to sign-up.
  2. Link to the issue

  3. What changed

    • File(s) and behavior: e.g. sendVerificationOTP in email-otp/routes.ts now throws USER_NOT_FOUND for sign-in when disableSignUp is true and the user doesn’t exist; test updated/added in email-otp.test.ts.
  4. Testing

    • ran pnpm -F better-auth test -- email-otp --run and it passes.
  5. Breaking / behavior change

    • Note that clients using disableSignUp: true with sign-in OTP will now get a 400 + USER_NOT_FOUND for non-existent emails instead of 200. No config or migration change.
  6. Target branch

    • Open the PR against canary.

Summary by cubic

Return 400 USER_NOT_FOUND for Email OTP sign-in when disableSignUp is enabled and the email has no account. This removes the ambiguous success response so apps can show “no account” messages and meets the needs of #7696.

  • Bug Fixes
    • Updated sendVerificationOTP to throw BAD_REQUEST with USER_NOT_FOUND for non-existent emails in sign-in when disableSignUp is true, and clear any pending verification for that identifier.
    • Updated tests to expect the error and verify no OTP is sent to unknown emails.

Written for commit 05e658e83d. 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/7704 **Author:** [@biniam0](https://github.com/biniam0) **Created:** 1/30/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/email-otp-user-not-found` --- ### 📝 Commits (1) - [`05e658e`](https://github.com/better-auth/better-auth/commit/05e658e83db38d23fb7b015fc3c0853cf74fe576) fix(email-otp): throw USER_NOT_FOUND when sign-up is disabled ### 📊 Changes **2 files changed** (+10 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/email-otp/email-otp.test.ts` (+4 -5) 📝 `packages/better-auth/src/plugins/email-otp/routes.ts` (+6 -1) </details> ### 📄 Description **PR description:** 1. **What & why** - When the Email OTP plugin was used with disableSignUp: true, calling sendVerificationOTP with type: "sign-in" for an unregistered email returned 200 with { success: true } instead of an error. That made it impossible for clients to tell “user not found” from “OTP sent,” and broke flows that rely on showing a “no account” message or redirecting to sign-up. 2. **Link to the issue** - Fixes #7696 3. **What changed** - File(s) and behavior: e.g. `sendVerificationOTP` in `email-otp/routes.ts` now throws `USER_NOT_FOUND` for sign-in when `disableSignUp` is true and the user doesn’t exist; test updated/added in `email-otp.test.ts`. 4. **Testing** - ran `pnpm -F better-auth test -- email-otp --run` and it passes. 5. **Breaking / behavior change** - Note that clients using `disableSignUp: true` with sign-in OTP will now get a 400 + `USER_NOT_FOUND` for non-existent emails instead of 200. No config or migration change. 6. **Target branch** - Open the PR against **canary**. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Return 400 USER_NOT_FOUND for Email OTP sign-in when disableSignUp is enabled and the email has no account. This removes the ambiguous success response so apps can show “no account” messages and meets the needs of #7696. - **Bug Fixes** - Updated sendVerificationOTP to throw BAD_REQUEST with USER_NOT_FOUND for non-existent emails in sign-in when disableSignUp is true, and clear any pending verification for that identifier. - Updated tests to expect the error and verify no OTP is sent to unknown emails. <sup>Written for commit 05e658e83db38d23fb7b015fc3c0853cf74fe576. 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-04-15 22:21:19 -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#24403