[PR #2616] [CLOSED] feat: allow overrideUserInfoOnSignIn to be a custom function #12649

Closed
opened 2026-04-13 08:30:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/2616
Author: @kylekz
Created: 5/11/2025
Status: Closed

Base: v1.3Head: feat/override-user-info-function


📝 Commits (4)

  • f958435 feat: allow overrideUserInfoOnSignIn to be a custom function
  • cb0f0ea provide email data to original adapter update
  • f441848 Merge branch 'v1.3' into pr/2616
  • 8492a8a handle server error

📊 Changes

7 files changed (+139 additions, -13 deletions)

View changed files

📝 docs/content/docs/concepts/oauth.mdx (+24 -0)
📝 packages/better-auth/src/oauth2/link-account.ts (+15 -5)
📝 packages/better-auth/src/oauth2/types.ts (+11 -1)
📝 packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts (+5 -1)
📝 packages/better-auth/src/plugins/generic-oauth/index.ts (+4 -1)
📝 packages/better-auth/src/plugins/sso/index.ts (+22 -5)
📝 packages/better-auth/src/social-providers/social.test.ts (+58 -0)

📄 Description

it makes sense for the user row to be created with data from the oauth provider, it doesn't always make sense for every field to be updated on every subsequent sign in.

consider the following scenarios:

1

  • user signs up using email/password with user@email.com
  • user links an oauth account that has a different email address
  • overrideUserInfoOnSignIn set to true now updates the user's email address

2

  • user signs up via oauth account using an email of user@email.com
  • mapProfileToUser sets the providerHandle custom column using profile.username
  • user signs back in using the same oauth account but has changed the handle on the account
  • overrideUserInfoOnSignIn set to true now updates the user's email address as well as the handle

using a custom updater function allows a middle ground between true and false. using this config, the user could be created with their email set from the provider, but subsequent signins would update their handle and only their handle

export const auth = betterAuth({
  socialProviders: {
    discord: {
      clientId: "YOUR_DISCORD_CLIENT_ID",
      clientSecret: "YOUR_DISCORD_CLIENT_SECRET",
      mapProfileToUser: (profile) => {
        return {
          discordHandle: profile.username,
        }
      },
      overrideUserInfoOnSignIn: (profile, { email, emailVerified }) => {
        return {
          name: profile.name,
          discordHandle: profile.username,
        };
      },
    },
  },
});

the email fields are a separate argument so they don't conflict with the actual oauth profile. only thing i'm unsure on is if this is just introducing repetition and that perhaps it should just be an array of values to include rather than a complete override of mapProfileToUser.


🔄 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/2616 **Author:** [@kylekz](https://github.com/kylekz) **Created:** 5/11/2025 **Status:** ❌ Closed **Base:** `v1.3` ← **Head:** `feat/override-user-info-function` --- ### 📝 Commits (4) - [`f958435`](https://github.com/better-auth/better-auth/commit/f95843573106c003b7077834c5a85a660bbc1689) feat: allow overrideUserInfoOnSignIn to be a custom function - [`cb0f0ea`](https://github.com/better-auth/better-auth/commit/cb0f0eadf6a4ea0e03fa43f5508a528f5b91700f) provide email data to original adapter update - [`f441848`](https://github.com/better-auth/better-auth/commit/f44184801515a921b528a7a2510a167bdf4987ca) Merge branch 'v1.3' into pr/2616 - [`8492a8a`](https://github.com/better-auth/better-auth/commit/8492a8aa35f85f704e81b3f2aaac7d402a419cc6) handle server error ### 📊 Changes **7 files changed** (+139 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/concepts/oauth.mdx` (+24 -0) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+15 -5) 📝 `packages/better-auth/src/oauth2/types.ts` (+11 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/generic-oauth.test.ts` (+5 -1) 📝 `packages/better-auth/src/plugins/generic-oauth/index.ts` (+4 -1) 📝 `packages/better-auth/src/plugins/sso/index.ts` (+22 -5) 📝 `packages/better-auth/src/social-providers/social.test.ts` (+58 -0) </details> ### 📄 Description it makes sense for the `user` row to be _created_ with data from the oauth provider, it doesn't always make sense for every field to be updated on every subsequent sign in. consider the following scenarios: ### 1 - user signs up using email/password with user@email.com - user links an oauth account that has a different email address - `overrideUserInfoOnSignIn` set to `true` now updates the user's email address ### 2 - user signs up via oauth account using an email of user@email.com - `mapProfileToUser` sets the `providerHandle` custom column using `profile.username` - user signs back in using the same oauth account but has changed the handle on the account - `overrideUserInfoOnSignIn` set to `true` now updates the user's email address as well as the handle using a custom updater function allows a middle ground between true and false. using this config, the user could be created with their email set from the provider, but subsequent signins would update their handle and only their handle ```ts export const auth = betterAuth({ socialProviders: { discord: { clientId: "YOUR_DISCORD_CLIENT_ID", clientSecret: "YOUR_DISCORD_CLIENT_SECRET", mapProfileToUser: (profile) => { return { discordHandle: profile.username, } }, overrideUserInfoOnSignIn: (profile, { email, emailVerified }) => { return { name: profile.name, discordHandle: profile.username, }; }, }, }, }); ``` the email fields are a separate argument so they don't conflict with the actual oauth profile. only thing i'm unsure on is if this is just introducing repetition and that perhaps it should just be an array of values to include rather than a complete override of `mapProfileToUser`. --- <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 08:30:59 -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#12649