[GH-ISSUE #1816] Account: unlinkAccount() functionality #26255

Closed
opened 2026-04-17 16:44:31 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @Phillip9587 on GitHub (Mar 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1816

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Signup a user
  2. Link a social provider
  3. try to remove the social provider with authClient.unlinkAccount()

Current vs. Expected behavior

Provider should be unlinked, but the route returns an error:
POST /api/auth/unlink-account 400

{
    "code": "YOU_CANT_UNLINK_YOUR_LAST_ACCOUNT",
    "message": "You can't unlink your last account"
}

This happens even when multiple providers are added. The invalid change was introduced in #1803. The unlinkAccount function now checks if a account with the same provider exists and throws if not. This completly breaks account unlinking.

765dd0d68f/packages/better-auth/src/api/routes/account.ts (L188-L196)

What version of Better Auth are you using?

1.2.4

Provide environment information

- OS: Ubuntu
- Browsers: Chrome and Firefox
- Node.js: v22.14.0

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

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  }, 
  socialProviders: {
    google: {
      clientId: '',
      clientSecret: '',
    },
    microsoft: {
      clientId: '',
      clientSecret: '',
      tenantId: 'common',
      requireSelectAccount: true,
    },
    github: {
      clientId: '',
      clientSecret: '',
    },
  },
});

Additional context

No response

Originally created by @Phillip9587 on GitHub (Mar 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1816 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Signup a user 2. Link a social provider 3. try to remove the social provider with `authClient.unlinkAccount()` ### Current vs. Expected behavior Provider should be unlinked, but the route returns an error: `POST /api/auth/unlink-account 400` ```json { "code": "YOU_CANT_UNLINK_YOUR_LAST_ACCOUNT", "message": "You can't unlink your last account" } ``` This happens even when multiple providers are added. The invalid change was introduced in #1803. The `unlinkAccount` function now checks if a account with the same provider exists and throws if not. This completly breaks account unlinking. https://github.com/better-auth/better-auth/blob/765dd0d68f3cb97329de245a436ebb02f1e0c2ea/packages/better-auth/src/api/routes/account.ts#L188-L196 ### What version of Better Auth are you using? 1.2.4 ### Provide environment information ```bash - OS: Ubuntu - Browsers: Chrome and Firefox - Node.js: v22.14.0 ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, socialProviders: { google: { clientId: '', clientSecret: '', }, microsoft: { clientId: '', clientSecret: '', tenantId: 'common', requireSelectAccount: true, }, github: { clientId: '', clientSecret: '', }, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 16:44:32 -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#26255