DeleteAccountForm
Permanent account deletion with password and typed DELETE confirmation.
Overview
DeleteAccountForm asks for the current password and a typed DELETE confirmation, then calls useDeleteAccount. On success it shows a short confirmation state with a control to reset the form.
Preview
Interactive preview requires JavaScript.
Install
npx @simpleauthjs/react add delete-account --style minimalThe install snippet uses --style minimal. You can also use --style modern. Style variants compares those two in the live preview. Run npx @simpleauthjs/react add --help for every --style slug the CLI accepts.
Props
| Name | Type | Required | Description |
|---|---|---|---|
onSuccess | () => void | No | Called after the account is deleted successfully (for example redirect home). |
Usage
Place this on a dedicated settings or danger-zone page inside a route that already requires a session.
"use client"
import { DeleteAccountForm } from "@/components/simpleauth"
export default function DangerZonePage() {
return <DeleteAccountForm onSuccess={() => (window.location.href = "/")} />
}Source
"use client"
import { useState } from "react"
import { SimpleAuthError, type SuccessResponse } from "@simpleauthjs/core"
import { useSimpleAuthClient } from "../provider"
function getErrorMessage(error: unknown) {
if (error instanceof SimpleAuthError) {
return error.message
}
if (error instanceof Error) {
return error.message
}
return "Unable to delete account."
}
export function useDeleteAccount() {
const auth = useSimpleAuthClient()
const [isLoading, setIsLoading] = useState(false)
const [error, setError] = useState<string | null>(null)
const [data, setData] = useState<SuccessResponse | null>(null)
async function deleteAccount(password: string) {
setIsLoading(true)
setError(null)
try {
const response = await auth.deleteAccount({ password })
setData(response)
return response
} catch (requestError) {
setData(null)
setError(getErrorMessage(requestError))
throw requestError
} finally {
setIsLoading(false)
}
}
function reset() {
setData(null)
setError(null)
setIsLoading(false)
}
return {
deleteAccount,
data,
error,
isError: Boolean(error),
isLoading,
isSuccess: Boolean(data?.success),
reset,
}
}
Customisation
Owned by you
Generated files live at components/simpleauth/ui/delete-account-form.tsx and components/simpleauth/styles/delete-account-form.css.