Skip to content
Torii docs

useDeleteAccount

useDeleteAccount() handles step one of account deletion: it validates the user’s type-to-confirm value on the server and emails them a one-time confirmation link. The account is not deleted until the user clicks that link; the SDK does not render the confirmation page.

  • Wire a “delete my account” button in your settings UI. Kept separate from useUserProfile() so the button doesn’t trigger an extra /me fetch.
import { useDeleteAccount } from '@torii-js/torii-react';
import { useState } from 'react';
function DeleteAccount({ email }: { email: string }) {
const { requestDeletion, isRequesting, error } = useDeleteAccount();
const [confirm, setConfirm] = useState('');
async function onDelete() {
const result = await requestDeletion(confirm);
if (result.ok) alert('Check your email to confirm deletion.');
}
return (
<>
<input
placeholder={`Type ${email} to confirm`}
value={confirm}
onChange={(e) => setConfirm(e.target.value)}
/>
<button disabled={isRequesting} onClick={onDelete}>Delete account</button>
{error && <p role="alert">{error.message}</p>}
</>
);
}
NameTypeDescription
requestDeletion(confirmation: string) => Promise<MutationResult<{ accepted: true }>>Validate the type-to-confirm value (the user’s email, compared case-insensitively) and email a confirmation link. Resolves a discriminated result; never throws. The session stays alive until the user confirms via the emailed link.
isRequestingbooleantrue while the request is in flight.
errorToriiError | nullThe ToriiError from the last request, or null. Branch on error.code; show error.message.
type MutationResult<T> =
| { ok: true; value: T }
| { ok: false; error: ToriiError };
  • Two-step flow: this hook only sends the email. The deletion itself happens on a server-rendered confirmation page the emailed link opens.
import type {
UseDeleteAccountReturn,
MutationResult,
ToriiError,
} from '@torii-js/torii-react';