Skip to main content

Overview

useRemoveAccount signs out and removes a specific account from the stored accounts map. It sends a best-effort sign-out request to the server to revoke the account’s refresh token family before removing local state. If the removed account is the currently active one, the SDK automatically switches to the next available account. If no other accounts remain, the SDK resets to the unauthenticated state.

Usage Example

import { useAccounts, useRemoveAccount } from "@replyke/react-js";

function AccountList() {
  const { accounts } = useAccounts();
  const { removeAccount, isRemoving, error } = useRemoveAccount();

  return (
    <ul>
      {accounts.map((account) => (
        <li key={account.id}>
          {account.name ?? account.email}
          <button
            onClick={() => removeAccount({ userId: account.id })}
            disabled={isRemoving}
          >
            Remove
          </button>
        </li>
      ))}
      {error && <p>{error}</p>}
    </ul>
  );
}

Parameters

The hook returns a removeAccount function that accepts:
userId
string
required
The ID of the account to remove.

Returns

removeAccount
function
Async function that removes the specified account. Throws synchronously if userId is not found in the accounts map or if no projectId is available. Runtime errors during removal are caught and surfaced via the error field instead of throwing.
isRemoving
boolean
true while the removal is in progress.
error
string | null
Error message if the removal failed, or null if no error occurred.

Integration Guide

For multi-account integration guidance, see Multi-Account.