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.
When to use it
Section titled “When to use it”- Wire a “delete my account” button in your settings UI. Kept separate from
useUserProfile()so the button doesn’t trigger an extra/mefetch.
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>} </> );}Returns
Section titled “Returns”| Name | Type | Description |
|---|---|---|
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. |
isRequesting | boolean | true while the request is in flight. |
error | ToriiError | null | The ToriiError from the last request, or null. Branch on error.code; show error.message. |
MutationResult
Section titled “MutationResult”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.
TypeScript
Section titled “TypeScript”import type { UseDeleteAccountReturn, MutationResult, ToriiError,} from '@torii-js/torii-react';