 // Redirect to login page or home page
                        window.location.href = "{% url 'app:login' %}";
                    })
                    .catch(error => {
                        console.error('Logout error:', error);
                        logoutBtn.disabled = false;
                        logoutBtn.innerHTML = 'Logout';
                        logoutBtn.classList.remove('opacity-50', 'cursor-not-allowed');
                        alert('Logout failed. Please try again.');
             