[PR #6908] [CLOSED] fix(two-factor): more than 1 twoFactor rows per user breaks #6959

Closed
opened 2026-03-13 13:19:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6908
Author: @ping-maxwell
Created: 12/20/2025
Status: Closed

Base: canaryHead: fix/two-factor/totp-duplicate-identifiers-breaks-verification


📝 Commits (3)

  • 73902a4 fix(two-factor): more than 1 twoFactor rows per user breaks
  • cffcb3c Merge branch 'canary' into fix/two-factor/totp-duplicate-identifiers-breaks-verification
  • 4cfb4f3 chore: lint

📊 Changes

1 file changed (+14 additions, -0 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/totp/index.ts (+14 -0)

📄 Description

Upon successful TOTP verification, we do not delete such row from DB. If the user were to do the same flow again, it would generate a new row in twoFactor table with that same userId field, then when using the verification endpoint, the findOne would only work sometimes as it may catch the old two-factor verification value and leads to a runtime invalid code error

NOTE:

I made it delete all rows related to that userId, this is because in the same endpoint code, we find the twoFactor row based on userId this same way. It could be that we need more requirements in the where clause, if so please let me know.


Summary by cubic

Delete all twoFactor rows for a user after successful TOTP verification. This prevents duplicate records from causing intermittent "invalid code" errors when findOne hits a stale entry.

Written for commit 4cfb4f3f8e. 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/6908 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 12/20/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/two-factor/totp-duplicate-identifiers-breaks-verification` --- ### 📝 Commits (3) - [`73902a4`](https://github.com/better-auth/better-auth/commit/73902a4bd92d24fb35a06ee2d8ba362ba25ea334) fix(two-factor): more than 1 twoFactor rows per user breaks - [`cffcb3c`](https://github.com/better-auth/better-auth/commit/cffcb3c599333f6152ae780c4a335a87babef361) Merge branch 'canary' into fix/two-factor/totp-duplicate-identifiers-breaks-verification - [`4cfb4f3`](https://github.com/better-auth/better-auth/commit/4cfb4f3f8eed8a69563b2b8e7598ae744ceca5ca) chore: lint ### 📊 Changes **1 file changed** (+14 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/totp/index.ts` (+14 -0) </details> ### 📄 Description Upon successful TOTP verification, we do not delete such row from DB. If the user were to do the same flow again, it would generate a new row in `twoFactor` table with that same `userId` field, then when using the verification endpoint, the `findOne` would only work sometimes as it may catch the old two-factor verification value and leads to a runtime `invalid code` error ### NOTE: I made it delete all rows related to that userId, this is because in the same endpoint code, we find the `twoFactor` row based on `userId` this same way. It could be that we need more requirements in the where clause, if so please let me know. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Delete all twoFactor rows for a user after successful TOTP verification. This prevents duplicate records from causing intermittent "invalid code" errors when findOne hits a stale entry. <sup>Written for commit 4cfb4f3f8eed8a69563b2b8e7598ae744ceca5ca. 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:19:09 -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#6959