18 lines
442 B
JavaScript
18 lines
442 B
JavaScript
const BASE = __API_URL__
|
|
|
|
export async function requireAuth() {
|
|
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(`${BASE}/whoami`, { credentials: 'include' })
|
|
if (res.ok) {
|
|
window.location.href = '/'
|
|
}
|
|
}
|