I’m currently having probably an easy issue… where I have 2 async handlers I’m trying to combine into 1 async function :
async function unsubscribeUserHandler() {
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 deleteUserHandler() {
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}`,
});
}
}
async function deleteAccount() {
let res = null;
try {
res = await Promise.all([
unsubscribeUserHandler(),
deleteUserHandler(),
]);
console.log('Success >>', res);
} catch (err) {
console.log('Fail >>', res, err);
}
}
const Settings = () => {
return (
<DeleteAccount onDeleteAccount={deleteAccount} />
)
}
If I return them individually, it either deletes the account from DB or unsubscribes from stripe. But if I return the handler, it only deletes the ACC from db… not does both. Am I missing something?