useDeleteAccount
useDeleteAccount() supports two deletion paths. Accounts with an email address
receive a one-time confirmation link. Email-less accounts reauthenticate with a
connected OAuth provider before the server deletes them.
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 user’s email and send a confirmation link. The session stays alive until the user confirms through that link. |
requestOAuthDeletion |
(provider: string) => Promise<MutationResult<{ redirecting: true }>> |
Redirect an email-less account to a connected provider. The account is deleted only when the callback proves the same provider identity owns it. |
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 };- Email-bearing accounts use
requestDeletionand complete deletion through the emailed confirmation page. - Email-less accounts use
requestOAuthDeletion, for examplerequestOAuthDeletion('github'). A different provider identity cannot delete the signed-in account.
TypeScript
Section titled “TypeScript”import type { UseDeleteAccountReturn, MutationResult, ToriiError,} from '@torii-js/torii-react';