[PR #3815] [CLOSED] fix(oauth2): compare accountId as forced string to prevent duplicates #21923

Closed
opened 2026-04-15 20:42:00 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3815
Author: @cemreinanc
Created: 8/5/2025
Status: Closed

Base: canaryHead: fix/duplicate-oauth-accounts


📝 Commits (2)

  • cf14968 fix(oauth2): compare accountId as forced string
  • 6143364 test and update

📊 Changes

2 files changed (+79 additions, -1 deletions)

View changed files

📝 packages/better-auth/src/oauth2/link-account.ts (+1 -1)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+78 -0)

📄 Description

in oauth2/link-account.ts file: accountId returns as a string from database but other one returns as a number from the endpoint. So they dont align and cause hasBeenLinked to be undefined.
in line 46 comparing like this a.accountId === String(account.accountId) seems like solved the issue.

Closes #3814


Summary by cubic

Fixed an issue where OAuth account linking could create duplicate accounts by ensuring accountId is always compared as a string.


🔄 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/3815 **Author:** [@cemreinanc](https://github.com/cemreinanc) **Created:** 8/5/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `fix/duplicate-oauth-accounts` --- ### 📝 Commits (2) - [`cf14968`](https://github.com/better-auth/better-auth/commit/cf14968a93e1b4e072813cd96e7391cab343759a) fix(oauth2): compare accountId as forced string - [`6143364`](https://github.com/better-auth/better-auth/commit/6143364b346a1295d08c2bd9f57a4d0cecd4e585) test and update ### 📊 Changes **2 files changed** (+79 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/oauth2/link-account.ts` (+1 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+78 -0) </details> ### 📄 Description in oauth2/link-account.ts file: `accountId` returns as a string from database but other one returns as a number from the endpoint. So they dont align and cause `hasBeenLinked` to be `undefined`. in line 46 comparing like this `a.accountId === String(account.accountId)` seems like solved the issue. Closes #3814 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed an issue where OAuth account linking could create duplicate accounts by ensuring accountId is always compared as a string. <!-- 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 20:42:00 -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#21923