import { component$ } from '@builder.io/qwik' import type { Client } from 'wildebeest/backend/src/mastodon/client' import { getClientById } from 'wildebeest/backend/src/mastodon/client' import { DocumentHead, loader$ } from '@builder.io/qwik-city' import { WildebeestLogo } from '~/components/MastodonLogo' import { Avatar } from '~/components/avatar' import { getPersonByEmail } from 'wildebeest/backend/src/activitypub/actors' import { getErrorHtml } from '~/utils/getErrorHtml/getErrorHtml' import { buildRedirect } from 'wildebeest/functions/oauth/authorize' import { getDatabase } from 'wildebeest/backend/src/database' import { getJwtEmail } from '~/utils/getJwtEmail' export const clientLoader = loader$>(async ({ platform, query, html }) => { const client_id = query.get('client_id') || '' let client: Client | null = null try { client = await getClientById(await getDatabase(platform), client_id) } catch (e: unknown) { const error = e as { stack: string; cause: string } console.warn(error.stack, error.cause) throw html(500, getErrorHtml('An error occurred while trying to fetch the client data, please try again later')) } if (client === null) { throw new Error('client not found') } return client }) export const userLoader = loader$>( async ({ cookie, platform, html, request, redirect, text }) => { const jwt = cookie.get('CF_Authorization') let email = '' try { email = getJwtEmail(jwt?.value ?? '') } catch (e) { throw html(500, getErrorHtml((e as Error)?.message)) } const person = await getPersonByEmail(await getDatabase(platform), email) if (person === null) { const isFirstLogin = true /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- jwt is defined otherwise getJwtEmail would have thrown */ const res = await buildRedirect(await getDatabase(platform), request as Request, isFirstLogin, jwt!.value) if (res.status === 302) { throw redirect(302, res.headers.get('location') || '') } else { throw text(res.status, await res.text()) } } const name = person.name const avatar = person.icon?.url const url = person.url if (!name || !avatar) { throw html(500, getErrorHtml("The person associated with the Access JWT doesn't include a name or avatar")) } return { email, avatar, name, url } } ) export default component$(() => { const client = clientLoader().value const { email, avatar, name: display_name, url } = userLoader().value return (


Signed in as:

{email}

Authorization required

{client.name} {' '} would like permission to access your account. It is a third-party application. If you do not trust it, then you should not authorize it.

Review permissions

Everything Read and write access
) }) export const head: DocumentHead = () => { return { title: 'Wildebeest Authorization required', meta: [ { name: 'description', content: 'Wildebeest Authorization required', }, ], } }