[PR #8552] Allow provider config to add extra fields to linked accounts #8057

Open
opened 2026-03-13 13:58:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8552
Author: @afn
Created: 3/11/2026
Status: 🔄 Open

Base: canaryHead: additional-account-fields


📝 Commits (2)

  • dd9b012 feat: allow provider config to add extra fields to linked accounts
  • 4b3db07 Fix linter errors

📊 Changes

6 files changed (+117 additions, -5 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.test.ts (+88 -0)
📝 packages/better-auth/src/api/routes/callback.ts (+8 -0)
📝 packages/better-auth/src/api/routes/sign-in.ts (+7 -1)
📝 packages/better-auth/src/oauth2/link-account.ts (+2 -4)
📝 packages/core/src/oauth2/oauth-provider.ts (+11 -0)
📝 pnpm-workspace.yaml (+1 -0)

📄 Description

This allows users to do things like add an additional column to the accounts table with the email address of the linked account (see #2272).

Example usage

export const auth = betterAuth({
  socialProviders: {
    google: {
      getAccountFields: async (_token, userInfo) => {
        // Use `token` to make additional API requests if needed.
        // Otherwise, extract relevant data from userInfo.
        return { providerEmail: userInfo.email };
      },
    },
  },
  account: {
    accountLinking: {
      allowDifferentEmails: true,
    },
    additionalFields: {
      providerEmail: {
        type: "string",
      },
    },
  },
});

Summary by cubic

Add a provider-level hook to populate extra fields on OAuth accounts. Also cleans up linter errors.

  • New Features

    • Added getAccountFields(tokens, userInfo) to provider options. Return an object to merge into the account record.
    • Applied on OAuth sign-in, account linking, and account updates. Undefined values are ignored.
    • Added test to confirm custom fields (e.g., foo, providerEmail) are persisted.
  • Migration

    • Define each new field under account.additionalFields to persist it in storage.
    • Implement getAccountFields in the provider (e.g., return { providerEmail: userInfo.email }).

Written for commit 4b3db07f1d7ccd3c6a6fe75df1f86c63af965e80. 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/8552 **Author:** [@afn](https://github.com/afn) **Created:** 3/11/2026 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `additional-account-fields` --- ### 📝 Commits (2) - [`dd9b012`](https://github.com/better-auth/better-auth/commit/dd9b0128366a72ada100e74a629781f8cb16c663) feat: allow provider config to add extra fields to linked accounts - [`4b3db07`](https://github.com/better-auth/better-auth/commit/4b3db07f1d7ccd3c6a6fe75df1f86c63af965e80) Fix linter errors ### 📊 Changes **6 files changed** (+117 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.test.ts` (+88 -0) 📝 `packages/better-auth/src/api/routes/callback.ts` (+8 -0) 📝 `packages/better-auth/src/api/routes/sign-in.ts` (+7 -1) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+2 -4) 📝 `packages/core/src/oauth2/oauth-provider.ts` (+11 -0) 📝 `pnpm-workspace.yaml` (+1 -0) </details> ### 📄 Description This allows users to do things like add an additional column to the accounts table with the email address of the linked account (see #2272). ## Example usage ```typescript export const auth = betterAuth({ socialProviders: { google: { getAccountFields: async (_token, userInfo) => { // Use `token` to make additional API requests if needed. // Otherwise, extract relevant data from userInfo. return { providerEmail: userInfo.email }; }, }, }, account: { accountLinking: { allowDifferentEmails: true, }, additionalFields: { providerEmail: { type: "string", }, }, }, }); ``` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a provider-level hook to populate extra fields on OAuth accounts. Also cleans up linter errors. - **New Features** - Added `getAccountFields(tokens, userInfo)` to provider options. Return an object to merge into the account record. - Applied on OAuth sign-in, account linking, and account updates. Undefined values are ignored. - Added test to confirm custom fields (e.g., `foo`, `providerEmail`) are persisted. - **Migration** - Define each new field under `account.additionalFields` to persist it in storage. - Implement `getAccountFields` in the provider (e.g., return `{ providerEmail: userInfo.email }`). <sup>Written for commit 4b3db07f1d7ccd3c6a6fe75df1f86c63af965e80. 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-03-13 13:58:34 -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#8057