Skip to main content

Account deletion

A customer may delete their account when logged in. To do so, the deleteCustomer mutation is used. The Flight framework contains a hook to assist with handling account deletion.

useDeleteAccountMutation()​

Arguments​

The hook takes an options object with the following keys:

confirmationMessage?: string @default "Are you sure you wish to delete your account?" Before deleting the account, the user will be prompted by a window.confirm dialog to give them the opportunity to cancel the action. confirmationMessage defines the string that will be shown in the dialog.

Returns​

An object is returned by the hook with the following keys:

confirmDeletion(): fn Shows a window.confirm dialog in the browser, and then proceeds to delete the user if they confirm. This will also clear the session cookie from the user's browser.

success: boolean Whether or not the user has been deleted. May be useful to redirect the user after deletion.

error: string Will contain an error message if an error occurs during the delete mutation.

Example usage:

const { confirmDeletion, error, success } = useDeleteAccountMutation({
confirmationMessage: "Really?",
});

if (success) {
return <Redirect to="/" />;
}

if (error) {
return <div style={errorStyle}>{error}</div>;
}

return <button onClick={confirmDeletion}>Delete my acount</button>;