[GH-ISSUE #7806] OAuth account linking fails when email casing differs between provider and existing account #19544

Closed
opened 2026-04-15 18:47:09 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @karuppusamy-d on GitHub (Feb 5, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7806

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create an account using a standard email/password provider with a lowercase email: johndoe@email.com.
  2. Attempt to sign in or link an account via an OAuth provider (e.g., Google or GitHub) where the primary email is returned with capital letters: JohnDoe@email.com.
  3. Observe that the linking process fails or creates a duplicate user instead of linking to the existing record.

Current vs. Expected behavior

Account linking fails during the OAuth flow if the email address returned by the OAuth provider has different casing than the email address already stored in the database.

While the email addresses are logically the same (e.g., johndoe@email.com and JohnDoe@email.com), the system treats them as distinct, preventing the automatic or manual linking of the OAuth identity to the existing user profile.

What version of Better Auth are you using?

1.4.13

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 4600H with Radeon Graphics         ",
    "totalMemory": "31.37 GB",
    "freeMemory": "12.41 GB"
  },
  "node": {
    "version": "v24.13.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.1.5"
    },
    {
      "name": "react",
      "version": "19.1.0"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.17.2"
    },
    {
      "name": "@prisma/client",
      "version": "7.3.0"
    }
  ],
  "betterAuth": {
    "version": "1.4.13",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  database: prismaAdapter(db, {
    provider: "postgresql",
  }),
  emailAndPassword: {  
    enabled: true
  },
  socialProviders: {
    google: {
      clientId: process.env["AUTH_GOOGLE_ID"] as string,
      clientSecret: process.env["AUTH_GOOGLE_SECRET"] as string,
      disableSignUp: true,
    },
  },
});

Additional context

No response

Originally created by @karuppusamy-d on GitHub (Feb 5, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7806 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create an account using a standard email/password provider with a lowercase email: johndoe@email.com. 2. Attempt to sign in or link an account via an OAuth provider (e.g., Google or GitHub) where the primary email is returned with capital letters: JohnDoe@email.com. 3. Observe that the linking process fails or creates a duplicate user instead of linking to the existing record. ### Current vs. Expected behavior Account linking fails during the OAuth flow if the email address returned by the OAuth provider has different casing than the email address already stored in the database. While the email addresses are logically the same (e.g., johndoe@email.com and JohnDoe@email.com), the system treats them as distinct, preventing the automatic or manual linking of the OAuth identity to the existing user profile. ### What version of Better Auth are you using? 1.4.13 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 4600H with Radeon Graphics ", "totalMemory": "31.37 GB", "freeMemory": "12.41 GB" }, "node": { "version": "v24.13.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "next", "version": "16.1.5" }, { "name": "react", "version": "19.1.0" } ], "databases": [ { "name": "pg", "version": "^8.17.2" }, { "name": "@prisma/client", "version": "7.3.0" } ], "betterAuth": { "version": "1.4.13", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ database: prismaAdapter(db, { provider: "postgresql", }), emailAndPassword: { enabled: true }, socialProviders: { google: { clientId: process.env["AUTH_GOOGLE_ID"] as string, clientSecret: process.env["AUTH_GOOGLE_SECRET"] as string, disableSignUp: true, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 18:47:09 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Feb 5, 2026):

It looks like you're experiencing issues with OAuth account linking due to email casing differences between the provider and the existing user account. This is a known limitation within the Better Auth framework, where email addresses are treated as distinct if their casing differs, leading to linking failures.

To address this issue, you can consider the following steps:

  1. Align Emails: Ensure the user is logging into the OAuth provider with the email address that matches the casing of the one used in your database. For instance, if the app account uses lowercase (johndoe@email.com), the user should log in with the same case.

  2. Check Provider Settings: Verify if the provider is returning a verified email. If users have multiple accounts with the provider, guide them in selecting the correct account that matches your app.

  3. Enable Different Email Linking: If your application allows it, consider enabling the allowDifferentEmails option in your configuration. This allows linking accounts that have different email addresses, which could help if casing variations are common.

  4. Inspect Local Logs: Log and compare the current user's email against the email returned by the OAuth provider. This may provide clarity on mismatches.

Here's a snippet for enabling different email linking in your config:

export const auth = betterAuth({
  account: {
    accountLinking: {
      enabled: true,
      allowDifferentEmails: true,
    },
  },
});

This setup will help accommodate linking despite the email mismatch.

If you need further assistance or if the problem persists, I recommend tagging the Better Auth team members, @bekacru and @ping__, for additional support.

What steps have you tried so far regarding this issue?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3853396241 --> @better-auth-agent[bot] commented on GitHub (Feb 5, 2026): It looks like you're experiencing issues with OAuth account linking due to email casing differences between the provider and the existing user account. This is a known limitation within the Better Auth framework, where email addresses are treated as distinct if their casing differs, leading to linking failures. To address this issue, you can consider the following steps: 1. **Align Emails**: Ensure the user is logging into the OAuth provider with the email address that matches the casing of the one used in your database. For instance, if the app account uses lowercase (`johndoe@email.com`), the user should log in with the same case. 2. **Check Provider Settings**: Verify if the provider is returning a verified email. If users have multiple accounts with the provider, guide them in selecting the correct account that matches your app. 3. **Enable Different Email Linking**: If your application allows it, consider enabling the `allowDifferentEmails` option in your configuration. This allows linking accounts that have different email addresses, which could help if casing variations are common. 4. **Inspect Local Logs**: Log and compare the current user's email against the email returned by the OAuth provider. This may provide clarity on mismatches. Here's a snippet for enabling different email linking in your config: ```typescript export const auth = betterAuth({ account: { accountLinking: { enabled: true, allowDifferentEmails: true, }, }, }); ``` This setup will help accommodate linking despite the email mismatch. If you need further assistance or if the problem persists, I recommend tagging the Better Auth team members, @bekacru and @ping__, for additional support. What steps have you tried so far regarding this issue? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19544