2025-05-06 21:11:52 -05:00

40 lines
938 B
Plaintext

<title>Login panel for admins</title>
<body>
<div>
<button
id="logout-button"
class="px-4 py-2 bg-white border border-gray-300 text-gray-800 rounded-md shadow-sm hover:bg-gray-100 hover:border-gray-400 transition-all"
>
Logout
</button>
</div>
<script>
document.getElementById('logout-button').addEventListener('click', function () {
fetch('/logout', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ action: 'logout' })
})
.then(response => {
if (!response.ok) {
throw new Error(`Logout failed: ${response.status}`);
}
return response.json(); // if you expect JSON back
})
.then(data => {
console.log('Logout successful:', data);
// window.location.href = '/login'; // redirect if needed
})
.catch(error => {
console.error('Error during logout:', error);
});
});
</script>
</body>