Show linked sign-in methods
Account management UI
Better Auth · Module
listAccounts retrieves every authentication method linked to the current user. Retain each returned account's id for unlinking or other account-specific operations.
Call authClient.listAccounts() to retrieve all authentication methods linked to the current user. The returned account records include an id that can be retained for account-specific operations such as unlinking or selecting an OAuth account.
authClient.listAccounts()A client response containing the current user's linked account records in data, or an error when the request fails.
id; a provider name alone is not the identifier needed for account-specific operations.import { createAuthClient } from "better-auth/client";
const authClient = createAuthClient();
const { data: accounts, error } = await authClient.listAccounts();
if (error) {
throw new Error(error.message);
}
for (const account of accounts ?? []) {
console.log(account.id, account.providerId);
}Creates a client, retrieves the signed-in user's linked authentication accounts, handles an error, and prints each account's identifier and provider.
Account management UI
Account removal
OAuth account selection
listAccounts return?It retrieves every authentication method linked to the currently authenticated user. The result is returned through the client response as data, alongside a possible error.
Follow-up: How would you select a Google account? Find the returned record whose providerId is google, then pass its id as accountId to the account-specific API.
Use const { data: accounts, error } = await authClient.listAccounts(). Check error before consuming accounts, because the client response can represent a failed request.
Follow-up: How should an application handle no linked accounts? Treat a missing or empty data collection as having no accounts and render the appropriate linking action.
The account record's id is the durable selector for later account operations, including unlinking. providerId identifies the provider but is not the account record identifier.
Follow-up: Why can providerId be insufficient? A user may have account-specific records and APIs require the Better Auth account id to select one precisely.
Account UnlinkinggetAccessTokenproviderIdaccountId