Remove a social provider
A user no longer wants a social-login provider attached to their profile.
Better Auth · Module
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.
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.
await authClient.unlinkAccount({ accountId: account.id });| Name | Type | Description |
|---|---|---|
accountId | string | The local Better Auth account record identifier returned by listAccounts. |
The page documents the operation and its errors but does not specify a return shape.
accountId field.allowUnlinkingAll to permit it.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.
A user no longer wants a social-login provider attached to their profile.
An account-management screen lets users maintain their linked authentication methods.
A user has multiple login methods and wants to reduce account connections.
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.
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.
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.
listAccountsaccountLinkingallowUnlinkingAll