interface AuthUser { id: number; username: string; } class AppNav extends HTMLElement { async connectedCallback(): Promise { const res = await fetch('/api/auth/me'); if (!res.ok) { location.href = '/login.html'; return; } const user = await res.json() as AuthUser; this.innerHTML = ` `; this.querySelector('.btn-logout')!.addEventListener('click', async () => { await fetch('/api/auth/logout', { method: 'POST' }); location.href = '/login.html'; }); this.querySelector('.btn-delete')!.addEventListener('click', async () => { if (!confirm('Delete your account? This cannot be undone.')) return; await fetch('/api/auth/me', { method: 'DELETE' }); location.href = '/login.html'; }); } } customElements.define('app-nav', AppNav);