add missing auth loader to settings page

pull/369/head
Dario Piotrowicz 2023-03-06 10:08:15 +00:00
rodzic 8ee894e5ed
commit db7f1bf13a
1 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -1,5 +1,19 @@
import { component$, Slot } from '@builder.io/qwik'
import { loader$ } from '@builder.io/qwik-city'
import { getDatabase } from 'wildebeest/backend/src/database'
import { WildebeestLogo } from '~/components/MastodonLogo'
import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml'
import { isUserAdmin } from '~/utils/isUserAdmin'
export const authLoader = loader$(async ({ cookie, platform, html }) => {
const database = await getDatabase(platform)
const jwt = cookie.get('CF_Authorization')?.value ?? ''
const isAdmin = await isUserAdmin(jwt, database)
if (!isAdmin) {
return html(401, getErrorHtml("You're unauthorized to view this page"))
}
})
export default component$(() => {
return (