Untitled
unknown
plain_text
2 years ago
1.4 kB
72
Indexable
deleteAccountBtn.addEventListener('click', async function () {
if (confirm('Are you sure you want to delete your account? This action cannot be undone.')) {
try {
// Fetch the current user's details
const { data: { user }, error } = await window.supabase.auth.getUser();
if (error) throw error;
// Insert a record into the deletionrequests table
const { error: deletionError } = await window.supabase
.from('deletionrequests')
.insert([{ user_id: user.id }]);
if (deletionError) {
console.error('Error requesting account deletion:', deletionError.message);
alert('Error: Failed to delete account.');
} else {
console.log('Deletion request submitted');
alert('Account deletion requested successfully. Please check your email for confirmation.');
await window.supabase.auth.signOut();
// Optionally, redirect to home page or login page
// window.location.href = '/';
}
} catch (error) {
console.error('Error:', error);
alert('An error occurred while trying to delete the account.');
}
}
});Editor is loading...
Leave a Comment