[PR #3302] [MERGED] fix: Use twoFactorEnabled flag instead of database lookup for OTP validation #30345

Closed
opened 2026-04-17 21:27:53 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3302
Author: @bairdj
Created: 7/8/2025
Status: Merged
Merged: 7/19/2025
Merged by: @Bekacru

Base: mainHead: fix/otp-enable-check


📝 Commits (2)

  • 0005df6 fix: remove redundant calls to two factor table
  • 965d6a7 fix lint

📊 Changes

1 file changed (+2 additions, -30 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/otp/index.ts (+2 -30)

📄 Description

Currently, the OTP part of the 2FA plugin checks that there is an existing entry in the twoFactor table before allowing OTP operations to continue.

However, for OTP (not TOTP) there is actually no need for the two factor table, because the generated code is not dependent on the secret. Therefore this call is redundant, and instead the enabled check should use twoFactorEnabled as in other parts of the code.

This PR:

  • Changes the check in /send-otp to check for twoFactorEnabled
  • Removes the check altogether in /verify-otp, which already has behaviour to update the twoFactorEnabled setting to true when a valid code is provided, therefore the check is unnecessary

🔄 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/3302 **Author:** [@bairdj](https://github.com/bairdj) **Created:** 7/8/2025 **Status:** ✅ Merged **Merged:** 7/19/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `main` ← **Head:** `fix/otp-enable-check` --- ### 📝 Commits (2) - [`0005df6`](https://github.com/better-auth/better-auth/commit/0005df6ff644a06c2d6acea3ccd3d81f6b356823) fix: remove redundant calls to two factor table - [`965d6a7`](https://github.com/better-auth/better-auth/commit/965d6a7036cb8854fd0f518dadb087ac52563ec2) fix lint ### 📊 Changes **1 file changed** (+2 additions, -30 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/otp/index.ts` (+2 -30) </details> ### 📄 Description Currently, the OTP part of the 2FA plugin checks that there is an existing entry in the `twoFactor` table before allowing OTP operations to continue. However, for OTP (not TOTP) there is actually no need for the two factor table, because the generated code is not dependent on the secret. Therefore this call is redundant, and instead the enabled check should use `twoFactorEnabled` as in other parts of the code. This PR: - Changes the check in `/send-otp` to check for `twoFactorEnabled` - Removes the check altogether in `/verify-otp`, which already has behaviour to update the `twoFactorEnabled` setting to true when a valid code is provided, therefore the check is unnecessary --- <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 21:27:53 -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#30345