Skip to main content

Overview

useRequestAccountDeletion returns a function that starts the self-service account-deletion flow for the currently authenticated user. It emails the user a 6-digit confirmation code (valid for 10 minutes) and does not delete anything on its own. Pass the code the user receives to useConfirmAccountDeletion to finish.
Only works for accounts with an email on file. Accounts without one (e.g. anonymous or foreign-id users) must be deleted server-side with a service key.

Usage Example

import { useRequestAccountDeletion } from "@sublay/react-js";

function DeleteAccountButton({ onCodeSent }: { onCodeSent: () => void }) {
  const requestAccountDeletion = useRequestAccountDeletion();

  const handleClick = async () => {
    try {
      await requestAccountDeletion();
      onCodeSent(); // reveal the "enter your code" step
    } catch (err: any) {
      // e.g. auth/no-email-on-file
      console.error(err.response?.data?.error ?? "Could not start deletion.");
    }
  };

  return <button onClick={handleClick}>Delete my account</button>;
}

Parameters

The returned function takes no arguments — it always acts on the currently authenticated user.

Returns

The hook returns an async function. That function resolves to:
success
boolean
true when the request completes without a server error.

See Also