create very rough UI
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
export async function login(username, password) {
|
||||
const form = new FormData()
|
||||
form.append('username', username)
|
||||
form.append('password', password)
|
||||
const res = await fetch('/api/login', { method: 'POST', body: form })
|
||||
if (!res.ok) throw new Error(await res.text())
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
const res = await fetch('/api/logout', { method: 'POST' })
|
||||
if (!res.ok) throw new Error(await res.text())
|
||||
}
|
||||
|
||||
export async function getchannels() {
|
||||
const res = await fetch('/api/channels')
|
||||
if (!res.ok) throw new Error(await res.text())
|
||||
return res.json()
|
||||
}
|
||||
|
||||
export async function getmessages(channelid, { from, to } = {}) {
|
||||
const params = new URLSearchParams()
|
||||
if (from) params.set('from', from.toISOString())
|
||||
if (to) params.set('to', to.toISOString())
|
||||
const query = params.size ? `?${params}` : ''
|
||||
const res = await fetch(`/api/channels/${channelid}/messages${query}`)
|
||||
if (!res.ok) throw new Error(await res.text())
|
||||
return res.json()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export async function requireAuth() {
|
||||
const res = await fetch('/api/whoami')
|
||||
if (res.status === 401) {
|
||||
window.location.href = '/login.html'
|
||||
}
|
||||
}
|
||||
|
||||
export async function redirectIfAuthed() {
|
||||
const res = await fetch('/api/whoami')
|
||||
if (res.ok) {
|
||||
window.location.href = '/'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// Alpine is initialized per-page inline in each HTML file
|
||||
Reference in New Issue
Block a user