The onBefore callback in InertiaJS does not support asynchronous functions. However, you can implement your own confirmation system by using a combination of promises and the window.confirm method.
Here's an example of how you can achieve this:
function showConfirm(message) {
return new Promise((resolve, reject) => {
const result = window.confirm(message);
if (result) {
resolve();
} else {
reject();
}
});
}
router.delete(`/users/${user.id}`, {
onBefore: () => showConfirm('Are you sure you want to delete this user?'),
})
.then(() => {
// User confirmed, proceed with the deletion
// Add your code here
})
.catch(() => {
// User canceled the confirmation, do nothing
});
In this example, the showConfirm function returns a promise that resolves if the user confirms the action and rejects if the user cancels it. You can then use the then and catch methods to handle the confirmation result and perform the appropriate actions.
Remember to replace the comment // Add your code here with the code that should be executed when the user confirms the deletion.
I hope this helps! Let me know if you have any further questions.