[PR #3712] [CLOSED] Fix: accountId condition being ignored and OAuth providerId type mismatch issue #4969

Closed
opened 2026-03-13 12:05:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3712
Author: @j-token
Created: 7/31/2025
Status: Closed

Base: mainHead: fix/oauth-prisma-persistent-login


📝 Commits (10+)

  • b0c2a30 Handle the case where accountId is a number.
  • be7af8b excute command pnpm changeset add
  • 93779d2 fix when cause error when accountID is undefined
  • 2e82f23 when accountId,providerId or email is undefined retrun null
  • c1af4ed If the type is defined, it is always parsed as a string.
  • e03e6b3 Merge branch 'main' into fix/oauth-prisma-persistent-login
  • 414c0dd If any of accountId, providerId, or email is not defined, treat it as if the account cannot be found.
  • abc3498 Merge branch 'fix/oauth-prisma-persistent-login' of https://github.com/codinglover0111/better-auth into fix/oauth-prisma-persistent-login
  • cc53947 make sure account match with account ID
  • 858d1a2 when accountId is number and exist then convert to string

📊 Changes

3 files changed (+18 additions, -9 deletions)

View changed files

.changeset/many-feet-sniff.md (+5 -0)
📝 packages/better-auth/src/adapters/kysely-adapter/test/state.txt (+1 -1)
📝 packages/better-auth/src/db/internal-adapter.ts (+12 -8)

📄 Description

1. Issue with all accounts being fetched when accountId is undefined

  • Issue Description:
    When accountId: undefined is included in the where condition in Prisma, the condition is ignored, and all accounts are fetched.
    As a result, when a user signs up via OAuth with the first account (a@google.com) in an empty database, the accountId of that account is always returned, causing incorrect login matching for all subsequent logins.

  • Solution:
    The accountId condition is only included when it explicitly exists, and the providerId filter is also applied to ensure accurate user matching.


2. OAuth provider id type mismatch (numberstring)

  • Issue Description:
    Some OAuth providers (such as Kakao) return profile.id as a number, but internal logic and database schemas expect it to be a string, causing a type mismatch.

  • Solution:
    Explicitly convert providerId values to strings using .toString() to maintain consistent handling across all providers.


Summary by cubic

Fixed an issue where accountId conditions were ignored in OAuth logins, causing incorrect account matching, and resolved a type mismatch by converting providerId values to strings.

  • Bug Fixes
    • Only include accountId in queries when defined to prevent fetching all accounts.
    • Ensure providerId is always a string for consistent matching across OAuth providers.

🔄 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/3712 **Author:** [@j-token](https://github.com/j-token) **Created:** 7/31/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/oauth-prisma-persistent-login` --- ### 📝 Commits (10+) - [`b0c2a30`](https://github.com/better-auth/better-auth/commit/b0c2a30f9499bdb7fb07676d3591d5bb00eccd87) Handle the case where accountId is a number. - [`be7af8b`](https://github.com/better-auth/better-auth/commit/be7af8bd622133ff18b6c20d9d7be3d1032dae4c) excute command pnpm changeset add - [`93779d2`](https://github.com/better-auth/better-auth/commit/93779d270ac95f7ffe2ed0c95adf8c824c93a6bb) fix when cause error when accountID is undefined - [`2e82f23`](https://github.com/better-auth/better-auth/commit/2e82f238a840b29fced1ac06dd066820e149fc8a) when accountId,providerId or email is undefined retrun null - [`c1af4ed`](https://github.com/better-auth/better-auth/commit/c1af4edc6720e26f5abca9d40f13ca1ad5a0954c) If the type is defined, it is always parsed as a string. - [`e03e6b3`](https://github.com/better-auth/better-auth/commit/e03e6b3367b2d779eef951f97a9f7f5b8246a559) Merge branch 'main' into fix/oauth-prisma-persistent-login - [`414c0dd`](https://github.com/better-auth/better-auth/commit/414c0ddb1015910eda9a218389ac2046403b59de) If any of accountId, providerId, or email is not defined, treat it as if the account cannot be found. - [`abc3498`](https://github.com/better-auth/better-auth/commit/abc3498c0f3c70bd7919de766d0e86464f397fea) Merge branch 'fix/oauth-prisma-persistent-login' of https://github.com/codinglover0111/better-auth into fix/oauth-prisma-persistent-login - [`cc53947`](https://github.com/better-auth/better-auth/commit/cc539471c704cdde83c4d565a3d8a10677d821b2) make sure account match with account ID - [`858d1a2`](https://github.com/better-auth/better-auth/commit/858d1a27ea632d9cec53addfe675ebb620a211c8) when accountId is number and exist then convert to string ### 📊 Changes **3 files changed** (+18 additions, -9 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/many-feet-sniff.md` (+5 -0) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/state.txt` (+1 -1) 📝 `packages/better-auth/src/db/internal-adapter.ts` (+12 -8) </details> ### 📄 Description ### 1. Issue with all accounts being fetched when `accountId` is `undefined` * **Issue Description**: When `accountId: undefined` is included in the `where` condition in Prisma, the condition is ignored, and all accounts are fetched. As a result, when a user signs up via OAuth with the first account (`a@google.com`) in an empty database, the `accountId` of that account is always returned, causing incorrect login matching for all subsequent logins. * **Solution**: The `accountId` condition is only included when it explicitly exists, and the `providerId` filter is also applied to ensure accurate user matching. --- ### 2. OAuth provider `id` type mismatch (`number` → `string`) * **Issue Description**: Some OAuth providers (such as Kakao) return `profile.id` as a `number`, but internal logic and database schemas expect it to be a `string`, causing a type mismatch. * **Solution**: Explicitly convert `providerId` values to strings using `.toString()` to maintain consistent handling across all providers. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed an issue where accountId conditions were ignored in OAuth logins, causing incorrect account matching, and resolved a type mismatch by converting providerId values to strings. - **Bug Fixes** - Only include accountId in queries when defined to prevent fetching all accounts. - Ensure providerId is always a string for consistent matching across OAuth providers. <!-- 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 12:05:52 -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#4969