[GH-ISSUE #1327] unlinkAccount does not work correctly #8693

Closed
opened 2026-04-13 03:51:18 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @vniehues on GitHub (Feb 1, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1327

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. create a new project with better-auth
  2. enable emailAndPassword and a social provider (eg. Github)
  3. Log the user in with emailAndPassword and link the GitHub account with a call to linkSocial like this:
await authClient.linkSocial({
    provider: "github",
    callbackURL: "/account/security"
})
  1. verify in the db that the account is linked and you can login with it.
  2. call unlinkAccount either from the client or the api like this:
await authClient.unlinkAccount({
    providerId: "github"
})
await auth.api.unlinkAccount({
    headers: request.headers,
    body: {
        providerId: "github"
    }
})
  1. the account will still be in the db and the user can still login with it.

the response indicates success (thats why the tests pass) but the database does not actually get an update

just in case these details matter:
Im using Prisma ORM and I set allowDifferentEmails: true in the config

Current vs. Expected behavior

current behavior:
currently the response indicates success but the database does not get updated

expected behavior:
the database actually gets updated when the response indicates success and the response indicates an error when it didn't work.

What version of Better Auth are you using?

1.1.15

Provide environment information

- OS: MacOS (latest) & Linux
- Browser: Safari, Chrome

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

Client, Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

export const auth = betterAuth({
    database: prismaAdapter(prisma, {
        provider: "postgresql"
    }),
    account: {
      accountLinking: {
          enabled: true,
          allowDifferentEmails: true
      }
    },
    socialProviders: {
        github: {
            clientId: process.env.GITHUB_CLIENT_ID,
            clientSecret: process.env.GITHUB_CLIENT_SECRET,
        },
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET,
        }
    },
    emailAndPassword: {
        enabled: true,
    },
    user: {
        additionalFields: {
            locale: {
                type: "string",
                required: false,
            }
        }
    },
    plugins: [
        admin(),
        organization(),
        passkey()
    ]
})
Originally created by @vniehues on GitHub (Feb 1, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1327 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. create a new project with better-auth 2. enable emailAndPassword and a social provider (eg. Github) 3. Log the user in with emailAndPassword and link the GitHub account with a call to linkSocial like this: ``` await authClient.linkSocial({ provider: "github", callbackURL: "/account/security" }) ``` 4. verify in the db that the account is linked and you can login with it. 5. call unlinkAccount either from the client or the api like this: ``` await authClient.unlinkAccount({ providerId: "github" }) ``` ``` await auth.api.unlinkAccount({ headers: request.headers, body: { providerId: "github" } }) ``` 6. the account will still be in the db and the user can still login with it. the response indicates success (thats why the tests pass) but the database does not actually get an update just in case these details matter: Im using Prisma ORM and I set `allowDifferentEmails: true` in the config ### Current vs. Expected behavior current behavior: currently the response indicates success but the database does not get updated expected behavior: the database actually gets updated when the response indicates success and the response indicates an error when it didn't work. ### What version of Better Auth are you using? 1.1.15 ### Provide environment information ```bash - OS: MacOS (latest) & Linux - Browser: Safari, Chrome ``` ### Which area(s) are affected? (Select all that apply) Client, Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context ``` export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql" }), account: { accountLinking: { enabled: true, allowDifferentEmails: true } }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET, }, google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, } }, emailAndPassword: { enabled: true, }, user: { additionalFields: { locale: { type: "string", required: false, } } }, plugins: [ admin(), organization(), passkey() ] }) ```
GiteaMirror added the lockedbug labels 2026-04-13 03:51:18 -05:00
Author
Owner

@vniehues commented on GitHub (Feb 1, 2025):

manually removing the account using direct db calls works as expected.
Fortunately that means we can currently work around this issue by just making direct db calls and just delete the account - this will prevent logins and let the user link the account again if they choose to.

<!-- gh-comment-id:2628918033 --> @vniehues commented on GitHub (Feb 1, 2025): manually removing the account using direct db calls works as expected. Fortunately that means we can currently work around this issue by just making direct db calls and just delete the account - this will prevent logins and let the user link the account again if they choose to.
Author
Owner

@matcastaneda commented on GitHub (Feb 2, 2025):

Hi! I have a question, how can you validate that if the email is already associated with another account, linking the account redirects to /account/security?error=account_already_linked_to_different_user instead of the default error page of Better Auth?

<!-- gh-comment-id:2629429297 --> @matcastaneda commented on GitHub (Feb 2, 2025): Hi! I have a question, how can you validate that if the email is already associated with another account, linking the account redirects to `/account/security?error=account_already_linked_to_different_user` instead of the default error page of 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#8693