async function cancelUserSubscriptionHandler() {
const unsubscribe = await fetch("/api/stripe-sessions/cancel-subscription", {
method: "PATCH",
body: JSON.stringify(),
headers: {
"Content-Type": "application/json",
},
});
const data = await unsubscribe.json();
if (!unsubscribe.ok) {
Toast.fire({
icon: "error",
title: `${data.message}`,
});
} else {
Toast.fire({
icon: "success",
title: `${data.message}`,
});
}
}
async function deleteUserAccountHandler() {
const deleteUser = await fetch("/api/user/delete-account", {
method: "DELETE",
body: JSON.stringify(),
headers: {
"Content-Type": "application/json",
},
});
const data = await deleteUser.json();
if (!deleteUser.ok) {
Toast.fire({
icon: "error",
title: `${data.message}`,
});
} else {
Toast.fire({
icon: "success",
title: `${data.message}`,
});
}
}
const deleteAccountProcess = async () => {
try {
await cancelUserSubscriptionHandler();
await deleteUserAccountHandler();
} catch (err) {
console.error('ERROR@@@@@!!!',err);
}
}
const SettingsPage = () => {
return <DeleteAccount onDeleteAccount={deleteAccountProcess} />;
};
As demonstrated above, the process involves canceling a user subscription before deleting the account.
A known issue is that only one handler is executed and not both. Is there an alternative approach?
I have attempted:
.then(() => deleteUserAccountHandler())
and
.then(deleteUserAccountHandler)
However, neither option calls the /api/user/delete-account endpoint,
resulting in only the unsubscription being performed.