[PR #5347] [MERGED] fix(two-factor): prisma issue #31548

Closed
opened 2026-04-17 22:26:33 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5347
Author: @okisdev
Created: 10/16/2025
Status: Merged
Merged: 1/10/2026
Merged by: @Bekacru

Base: canaryHead: fix(two-factor)/prisma-issue


📝 Commits (10+)

  • 317afca fix(two-factor): prisma issue
  • c162b1d fix(two-factor): prisma issue
  • a9fac9d fix(two-factor): prisma issue
  • 29e2829 fix(two-factor): prisma issue
  • 9e1cf79 fix(two-factor): prisma issue
  • fa4cbc2 fix(two-factor): prisma issue
  • 2bf7ed1 fix(two-factor): prisma issue
  • bae0930 fix(two-factor): prisma issue
  • 050e876 fix(two-factor): prisma issue
  • 77642e3 Apply suggestion from @Bekacru

📊 Changes

3 files changed (+139 additions, -6 deletions)

View changed files

📝 packages/better-auth/src/plugins/two-factor/backup-codes/index.ts (+27 -6)
📝 packages/better-auth/src/plugins/two-factor/two-factor.test.ts (+111 -0)
📝 packages/better-auth/src/plugins/two-factor/types.ts (+1 -0)

📄 Description

This PR fixes a critical issue where Prisma adapter operations were failing when updating two-factor authentication records.

fix https://github.com/better-auth/better-auth/issues/5331


Summary by cubic

Fixes Prisma adapter failures in two-factor flows by updating records using the unique two-factor id instead of userId. This makes backup code generation, viewing, and verification reliable.

  • Bug Fixes
    • Replace updateMany (userId) with update (id) for backup code updates.
    • Fetch twoFactor by userId to get id; throw TWO_FACTOR_NOT_ENABLED when missing.
    • Add id to TwoFactorTable to support unique updates.
    • Expand tests to cover repeated regeneration, removal of used codes, and parsed viewing.

Written for commit da42d0a2c4. 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/5347 **Author:** [@okisdev](https://github.com/okisdev) **Created:** 10/16/2025 **Status:** ✅ Merged **Merged:** 1/10/2026 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix(two-factor)/prisma-issue` --- ### 📝 Commits (10+) - [`317afca`](https://github.com/better-auth/better-auth/commit/317afca685705e6ea4c2248aee5151a5440e0a6f) fix(two-factor): prisma issue - [`c162b1d`](https://github.com/better-auth/better-auth/commit/c162b1dea6b7a25223edc9c3954f1b943e7bd507) fix(two-factor): prisma issue - [`a9fac9d`](https://github.com/better-auth/better-auth/commit/a9fac9db631313f657a71c1a750339d9d6f05b86) fix(two-factor): prisma issue - [`29e2829`](https://github.com/better-auth/better-auth/commit/29e2829e78420ff6da6fb5d122df6b1d679e244c) fix(two-factor): prisma issue - [`9e1cf79`](https://github.com/better-auth/better-auth/commit/9e1cf79e169cf17d62b6b78f40bc411d3907fcaf) fix(two-factor): prisma issue - [`fa4cbc2`](https://github.com/better-auth/better-auth/commit/fa4cbc21d52284c24598468ffdcd301a7e349682) fix(two-factor): prisma issue - [`2bf7ed1`](https://github.com/better-auth/better-auth/commit/2bf7ed13e0786cf038a39fb0fecfcdafc50d2ee4) fix(two-factor): prisma issue - [`bae0930`](https://github.com/better-auth/better-auth/commit/bae09305cb29bb21c554e613d2508ac8d011346e) fix(two-factor): prisma issue - [`050e876`](https://github.com/better-auth/better-auth/commit/050e876323b4f4c66800f8c00d5d1438cd695202) fix(two-factor): prisma issue - [`77642e3`](https://github.com/better-auth/better-auth/commit/77642e3faf4ee1f2aa75de637e453cbe0153730b) Apply suggestion from @Bekacru ### 📊 Changes **3 files changed** (+139 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/two-factor/backup-codes/index.ts` (+27 -6) 📝 `packages/better-auth/src/plugins/two-factor/two-factor.test.ts` (+111 -0) 📝 `packages/better-auth/src/plugins/two-factor/types.ts` (+1 -0) </details> ### 📄 Description This PR fixes a critical issue where Prisma adapter operations were failing when updating two-factor authentication records. fix https://github.com/better-auth/better-auth/issues/5331 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes Prisma adapter failures in two-factor flows by updating records using the unique two-factor id instead of userId. This makes backup code generation, viewing, and verification reliable. - **Bug Fixes** - Replace updateMany (userId) with update (id) for backup code updates. - Fetch twoFactor by userId to get id; throw TWO_FACTOR_NOT_ENABLED when missing. - Add id to TwoFactorTable to support unique updates. - Expand tests to cover repeated regeneration, removal of used codes, and parsed viewing. <sup>Written for commit da42d0a2c4e59f674b47ec96d2aef25e6b6d66f9. 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-17 22:26:33 -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#31548