Add logout button to header
Adds a logout button in the top bar on authenticated pages. Posts to /api/auth/logout to clear the server session, then redirects to login. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ const NextSnap = {
|
||||
console.log(`NextSnap v${this.version} initializing...`);
|
||||
this.setupConnectivityMonitoring();
|
||||
this.setupServiceWorkerMessaging();
|
||||
this.setupLogout();
|
||||
this.checkHealth();
|
||||
},
|
||||
|
||||
@@ -79,6 +80,17 @@ const NextSnap = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
setupLogout() {
|
||||
const btn = document.getElementById('logoutBtn');
|
||||
if (!btn) return;
|
||||
btn.addEventListener('click', async () => {
|
||||
try {
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
} catch (e) { /* offline - clear locally anyway */ }
|
||||
window.location.href = '/login';
|
||||
});
|
||||
},
|
||||
// Force service worker update
|
||||
async updateServiceWorker() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
|
||||
Reference in New Issue
Block a user