[PR #8925] [CLOSED] [codex] Fix provider-aware social link lookup #16547

Closed
opened 2026-04-13 10:34:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8925
Author: @skirdey
Created: 4/2/2026
Status: Closed

Base: mainHead: codex/fix-provider-aware-link-lookup


📝 Commits (1)

  • d0ceaf9 Fix provider-aware social link lookup

📊 Changes

2 files changed (+252 additions, -3 deletions)

View changed files

packages/better-auth/src/api/routes/callback-link-account.test.ts (+247 -0)
📝 packages/better-auth/src/api/routes/callback.ts (+5 -3)

📄 Description

Summary

  • use a provider-aware lookup in the social link callback so matching is scoped by both accountId and providerId
  • add a focused regression test that links Google and GitHub accounts sharing the same external id and asserts both linked rows are preserved

Root Cause

The link callback was calling findAccount(String(userInfo.id)), which searches only by external account id. When two different providers return the same external id, the callback could update the wrong linked account row instead of creating or updating the provider-specific row.

Impact

  • prevents cross-provider account collisions during social account linking
  • keeps provider-specific linked accounts intact when external ids overlap

Validation

  • pnpm build
  • pnpm --filter better-auth test --run src/api/routes/callback-link-account.test.ts

Closes #8906


Summary by cubic

Fixes social account linking by looking up linked accounts by both external id and provider, preventing cross-provider collisions. Adds a regression test to ensure Google and GitHub accounts with the same external id are stored as separate links.

  • Bug Fixes
    • Replaced findAccount with findAccountByProviderId(accountId, providerId) in packages/better-auth/src/api/routes/callback.ts.
    • Added callback-link-account.test.ts to verify both Google and GitHub links are preserved when sharing the same external id.

Written for commit d0ceaf9325. 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/8925 **Author:** [@skirdey](https://github.com/skirdey) **Created:** 4/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `codex/fix-provider-aware-link-lookup` --- ### 📝 Commits (1) - [`d0ceaf9`](https://github.com/better-auth/better-auth/commit/d0ceaf932505e4fff529476a485a678c13091c90) Fix provider-aware social link lookup ### 📊 Changes **2 files changed** (+252 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `packages/better-auth/src/api/routes/callback-link-account.test.ts` (+247 -0) 📝 `packages/better-auth/src/api/routes/callback.ts` (+5 -3) </details> ### 📄 Description ## Summary - use a provider-aware lookup in the social link callback so matching is scoped by both `accountId` and `providerId` - add a focused regression test that links Google and GitHub accounts sharing the same external id and asserts both linked rows are preserved ## Root Cause The link callback was calling `findAccount(String(userInfo.id))`, which searches only by external account id. When two different providers return the same external id, the callback could update the wrong linked account row instead of creating or updating the provider-specific row. ## Impact - prevents cross-provider account collisions during social account linking - keeps provider-specific linked accounts intact when external ids overlap ## Validation - `pnpm build` - `pnpm --filter better-auth test --run src/api/routes/callback-link-account.test.ts` Closes #8906 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes social account linking by looking up linked accounts by both external id and provider, preventing cross-provider collisions. Adds a regression test to ensure Google and GitHub accounts with the same external id are stored as separate links. - **Bug Fixes** - Replaced `findAccount` with `findAccountByProviderId(accountId, providerId)` in `packages/better-auth/src/api/routes/callback.ts`. - Added `callback-link-account.test.ts` to verify both Google and GitHub links are preserved when sharing the same external id. <sup>Written for commit d0ceaf932505e4fff529476a485a678c13091c90. 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-13 10:34:10 -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#16547