Skip to main content

Overview

useConfirmAccountDeletion returns a function that submits the confirmation code from useRequestAccountDeletion and permanently deletes the authenticated user’s account. On success, the local session is torn down just like a sign-out: the deleted account is removed from the multi-account map, and the SDK switches to a remaining signed-in account if there is one (otherwise the user is fully logged out).
Deletion is immediate and irreversible. There is no grace period and no recovery once this resolves.

Usage Example

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

function ConfirmDeletionForm() {
  const confirmAccountDeletion = useConfirmAccountDeletion();
  const [code, setCode] = useState("");
  const [error, setError] = useState("");

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    setError("");
    try {
      await confirmAccountDeletion({ code });
      // Account is gone and the session has been cleared.
    } catch (err: any) {
      setError(err.message ?? "Deletion failed.");
    }
  };

  return (
    <form onSubmit={handleSubmit}>
      {error && <p>{error}</p>}
      <input
        value={code}
        onChange={(e) => setCode(e.target.value)}
        placeholder="Enter the code from your email"
      />
      <button type="submit">Permanently delete my account</button>
    </form>
  );
}

Parameters

The returned function accepts:
code
string
required
The one-time confirmation code the user received by email. Must match the most recently issued code exactly.

Returns

The hook returns an async function that resolves to void on success. It throws if the code is invalid or expired, or if the deletion fails.
You don’t need to call signOut afterward — the hook clears the local session for you and switches to a remaining account if the user had several signed in.

See Also