ui: align js with api

This commit is contained in:
2026-06-03 01:30:38 +00:00
parent 007e61bca1
commit b29520c5af
4 changed files with 77 additions and 22 deletions
+6 -2
View File
@@ -1,12 +1,16 @@
const BASE = __API_URL__
export async function requireAuth() {
const res = await fetch('/api/whoami')
const res = await fetch(`${BASE}/whoami`, { credentials: 'include' })
if (res.status === 401) {
window.location.href = '/login.html'
return null
}
return res.text()
}
export async function redirectIfAuthed() {
const res = await fetch('/api/whoami')
const res = await fetch(`${BASE}/whoami`, { credentials: 'include' })
if (res.ok) {
window.location.href = '/'
}