document.getElementById('f').onsubmit = async e => { e.preventDefault(); const msg = document.getElementById('msg'); msg.textContent = ''; const r = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: (document.getElementById('name') as HTMLInputElement).value, password: (document.getElementById('pw') as HTMLInputElement).value, }), }); if (r.ok) location.href = '/'; else msg.textContent = await r.text() || 'Sign in failed'; };