This commit is contained in:
Markos Gogoulos 2025-10-18 17:02:46 +03:00
parent 17b8c60450
commit 0f6d965f54
2 changed files with 41 additions and 1 deletions

View File

@ -99,6 +99,46 @@ function popupMiddleNavItems() {
text: translateString('Change password'),
});
}
items.push({
itemType: 'button',
icon: 'delete_forever',
text: translateString('Delete account'),
buttonAttr: {
onClick: (e) => {
e.preventDefault();
const confirmed = window.confirm(
'Are you sure you want to delete your account? This action cannot be undone and will permanently remove all your data, including your media and playlists.'
);
if (confirmed) {
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]')?.value ||
document.cookie.split('; ').find(row => row.startsWith('csrftoken='))?.split('=')[1];
fetch(`/api/v1/users/${user.username}`, {
method: 'DELETE',
headers: {
'X-CSRFToken': csrfToken,
},
})
.then((response) => {
if (response.ok) {
alert('Your account has been deleted successfully. You will be redirected to the home page.');
window.location.href = '/';
} else {
return response.json().then((data) => {
throw new Error(data.detail || 'Failed to delete account.');
});
}
})
.catch((error) => {
alert('Error deleting account: ' + error.message);
console.error('Error deleting account:', error);
});
}
},
},
});
}
return items;

File diff suppressed because one or more lines are too long