fix: auth/me check on load

This commit is contained in:
Chris Christiansen 2026-06-24 14:46:52 +00:00
parent ea9fadb3e0
commit c27a783388

View File

@ -794,9 +794,22 @@ async function pollBuild(){
return null
}
}
document.addEventListener('DOMContentLoaded', () => {
document.addEventListener('DOMContentLoaded', async () => {
// Sjekk auth-status
try {
const r = await fetch('/auth/me')
if(r.ok){
const u = await r.json()
document.getElementById('sb-session').textContent = u.email || 'innlogget'
document.getElementById('send-btn').disabled = false
} else {
window.location.href = '/auth/login'
}
} catch(e) {
document.getElementById('sb-session').textContent = 'session: feil'
}
pollBuild()
setInterval(pollBuild,30000)
setInterval(pollBuild, 30000)
})
// ─── Fix 3: CostGuard — fetchWithTimeout helper (AbortController, 10s) ───