Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Module

unlinkAccount

unlinkAccount removes one authentication method from the current user. Select the account with listAccounts, then pass its local record ID as accountId; the last account is protected by default.

How it works

Call unlinkAccount with the local account record's id, typically obtained from listAccounts. Better Auth rejects missing or foreign accounts and normally blocks removal of a user's last account unless account-linking configuration enables allowUnlinkingAll.

Syntax

await authClient.unlinkAccount({ accountId: account.id });

Parameters

NameTypeDescription
accountIdstringThe local Better Auth account record identifier returned by listAccounts.

Returns

The page documents the operation and its errors but does not specify a return shape.

Key points

  • Retrieve the user's linked authentication methods before presenting an unlink option.
  • Store each returned local account ID for subsequent account-specific operations.
  • Pass the local record ID through the accountId field.
  • Invalid or чужой account selections produce an error rather than removing an account.
  • The default safety rule keeps at least one authentication method linked.

Common mistakes

  • The selected account must exist and belong to the signed-in user; otherwise the operation fails.
  • Unlinking the sole account is blocked by default; enable allowUnlinkingAll to permit it.

Example: Unlink a linked account

import { authClient } from "@/lib/auth-client";

const { data: accounts, error } = await authClient.listAccounts();
if (error) throw new Error(error.message);

const account = accounts?.find((item) => item.providerId === "google");
if (account) {
  await authClient.unlinkAccount({ accountId: account.id });
}

Lists the current user's accounts, selects the Google account, and removes it using its local account ID.

When to use it

Remove a social provider

A user no longer wants a social-login provider attached to their profile.

Self-service credential management

An account-management screen lets users maintain their linked authentication methods.

Reduce linked identities

A user has multiple login methods and wants to reduce account connections.

Interview questions

QHow do you safely choose an account to unlink?

Use listAccounts to obtain the current user's account records, then pass the chosen record's local id as accountId to unlinkAccount. This avoids selecting an account that is not owned by the current user.

Follow-up: What should happen when the requested account is invalid? The API returns an error if the account is missing or belongs to another user.

QWhat happens when a user tries to unlink their last account?

By default, Better Auth prevents unlinking the user's only account. The restriction avoids leaving the user without any authentication method.

Follow-up: How can an application override this protection? Set the account-linking option allowUnlinkingAll to true.

QWhat identifier does unlinkAccount require?

The client call is authClient.unlinkAccount({ accountId: account.id }), where account.id comes from listAccounts. The account ID is the local Better Auth record ID.

Follow-up: Why should the provider-side account identifier not be used? The account-specific selector expects the local account record's id, not the provider's account identifier.

  • listAccounts
  • accountLinking
  • allowUnlinkingAll

Source: User & Accounts | Better Auth. Checked 2026-10-15.