allowDifferentEmails is not respected #1875

Closed
opened 2026-03-13 09:10:08 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @michalwerner on GitHub (Sep 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When manually connecting social account by e.g.:

await authClient.linkSocial({
  provider: "google",
});

it's possible to connect account with different email despite allowDifferentEmails is set to false.

This is most likely because check for that is inside if (c.body.idToken) block which effectively skips this check for the flow without idToken.

I can prepare a PR to fix that, but first I'd like to ask if this is maybe intentional for some reason.

Current vs. Expected behavior

Current: allowDifferentEmails is NOT respected in social account linking without idToken

Expected: allowDifferentEmails IS respected in social account linking without idToken

What version of Better Auth are you using?

1.3.8

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000",
    "release": "24.5.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.11 GB"
  },
  "node": {
    "version": "v22.18.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "9.13.2"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null,
    "error": "ENOENT: no such file or directory, open 'package.json'"
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Client, Documentation

Auth config (if applicable)

{
  socialProviders: {
    google: {
      prompt: "select_account",
      clientId: process.env.BETTER_AUTH_GOOGLE_CLIENT_ID!,
      clientSecret: process.env.BETTER_AUTH_GOOGLE_CLIENT_SECRET,
      mapProfileToUser: (profile) => ({
        firstName: profile.given_name,
        lastName: profile.family_name,
      }),
    },
  },
  account: {
    encryptOAuthTokens: true,
    updateAccountOnSignIn: true,
    accountLinking: {
      enabled: true,
      allowDifferentEmails: false,
    },
  },
}

Additional context

No response

Originally created by @michalwerner on GitHub (Sep 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When manually connecting social account by e.g.: ```ts await authClient.linkSocial({ provider: "google", }); ``` it's possible to connect account with different email despite `allowDifferentEmails` is set to `false`. This is most likely because [check for that](https://github.com/better-auth/better-auth/blob/9829c4dea2536bdc9396b3ee9a8ae7d5273944f8/packages/better-auth/src/api/routes/account.ts#L299) is inside [`if (c.body.idToken)` block](https://github.com/better-auth/better-auth/blob/9829c4dea2536bdc9396b3ee9a8ae7d5273944f8/packages/better-auth/src/api/routes/account.ts#L220C3-L220C24) which effectively skips this check for the flow without `idToken`. I can prepare a PR to fix that, but first I'd like to ask if this is maybe intentional for some reason. ### Current vs. Expected behavior Current: `allowDifferentEmails` is NOT respected in social account linking without `idToken` Expected: `allowDifferentEmails` IS respected in social account linking without `idToken` ### What version of Better Auth are you using? 1.3.8 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000", "release": "24.5.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.11 GB" }, "node": { "version": "v22.18.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "9.13.2" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null, "error": "ENOENT: no such file or directory, open 'package.json'" } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client, Documentation ### Auth config (if applicable) ```typescript { socialProviders: { google: { prompt: "select_account", clientId: process.env.BETTER_AUTH_GOOGLE_CLIENT_ID!, clientSecret: process.env.BETTER_AUTH_GOOGLE_CLIENT_SECRET, mapProfileToUser: (profile) => ({ firstName: profile.given_name, lastName: profile.family_name, }), }, }, account: { encryptOAuthTokens: true, updateAccountOnSignIn: true, accountLinking: { enabled: true, allowDifferentEmails: false, }, }, } ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 09:10:08 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 7, 2025):

Hi @michalwerner! I'm Dosu and I’m helping the better-auth team.

You're correct—right now, the allowDifferentEmails check is only enforced inside the if (c.body.idToken) block in the backend, so if idToken isn't present, the check is skipped and users can link accounts with different emails even if allowDifferentEmails is false. There's no comment or code suggesting this is intentional, and I couldn't find any documentation or prior discussion explaining this behavior. It looks like an oversight rather than a deliberate design choice, so proposing a PR to enforce allowDifferentEmails consistently across all social linking flows would be appropriate. You can see the relevant code and logic here: account.ts implementation.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Sep 7, 2025): <!-- Greeting --> Hi @michalwerner! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're correct—right now, the allowDifferentEmails check is only enforced inside the if (c.body.idToken) block in the backend, so if idToken isn't present, the check is skipped and users can link accounts with different emails even if allowDifferentEmails is false. There's no comment or code suggesting this is intentional, and I couldn't find any documentation or prior discussion explaining this behavior. It looks like an oversight rather than a deliberate design choice, so proposing a PR to enforce allowDifferentEmails consistently across all social linking flows would be appropriate. You can see the relevant code and logic here: [account.ts implementation](https://github.com/better-auth/better-auth/blob/a7eaa049e448464ad8501f46136048091a072f43/packages/better-auth/src/api/routes/account.ts). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2ca61668-0340-4935-9e5b-f162ee0d3214?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/4503)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1875