refactor: ♻️ Rewrite OAuth consent UI

This commit is contained in:
Jesse Wierzbinski 2024-12-02 23:32:13 +01:00
parent 8d618d5e7f
commit 7cd71f252e
No known key found for this signature in database
5 changed files with 46 additions and 85 deletions

View file

@ -31,6 +31,7 @@ const appData = useAppData();
const instance = useInstance();
const description = useExtendedDescription(client);
const customCss = useSetting(SettingIds.CustomCSS);
const route = useRoute();
useSeoMeta({
titleTemplate: (titleChunk) => {
@ -61,7 +62,7 @@ useHead({
],
});
if (code && appData.value) {
if (code && appData.value && route.path !== "/oauth/code") {
signInWithCode(code, appData.value);
}

View file

@ -14,15 +14,18 @@ const instance = useInstanceFromClient(new Client(new URL(useBaseUrl().value)));
</script>
<template>
<div
class="container relative flex h-svh flex-col items-center justify-center md:flex-row lg:max-w-none lg:px-0">
<div class="container relative flex h-svh flex-col items-center justify-center md:flex-row lg:max-w-none lg:px-0">
<Button :as="NuxtLink" href="/register" variant="link" class="absolute right-4 top-4 md:right-8 md:top-8">
Register
</Button>
<div class="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex grow">
<div class="absolute inset-0 bg-zinc-900" />
<div class="relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex grow bg-center bg-no-repeat bg-cover"
:style="{
backgroundImage: 'url(/images/banner.webp)'
}">
<div class="absolute top-0 left-0 w-full h-72 bg-gradient-to-t from-transparent to-black/70" />
<div class="relative z-20 flex items-center text-lg font-medium">
<img crossorigin="anonymous" :src="instance?.thumbnail.url || 'https://cdn.versia.pub/branding/icon.svg'" alt="Versia logo"
<img crossorigin="anonymous"
:src="instance?.thumbnail.url || 'https://cdn.versia.pub/branding/icon.svg'" alt="Versia logo"
class="size-10 mr-4" />
{{ instance?.title }}
</div>

View file

@ -1,5 +1,7 @@
<template>
<div class="h-svh flex items-center justify-center px-4">
<div class="h-svh flex items-center justify-center px-4 bg-center bg-no-repeat bg-cover" :style="{
backgroundImage: 'url(/images/banner.webp)'
}">
<Card class="w-full max-w-md">
<CardHeader>
<CardTitle>Here's your code</CardTitle>
@ -7,8 +9,7 @@
</CardDescription>
</CardHeader>
<CardContent class="grid">
<code
class="rounded bg-muted px-4 py-2 border text-center w-full font-mono text-sm font-semibold select-all">{{ code }}</code>
<pre class="rounded bg-muted px-4 py-2 border text-center w-full font-mono text-sm font-semibold select-all">{{ code }}</pre>
</CardContent>
</Card>
</div>
@ -23,7 +24,5 @@ import {
CardTitle,
} from "~/components/ui/card";
const params = useUrlSearchParams();
const code = params.code;
const { code } = useUrlSearchParams();
</script>

View file

@ -1,89 +1,47 @@
<template>
<div class="flex min-h-screen relative flex-col justify-center px-6 py-12 lg:px-8">
<div v-if="validUrlParameters" class="sm:mx-auto sm:w-full sm:max-w-sm">
<form class="space-y-6" method="POST" :action="url.pathname.replace('/oauth/consent', '/oauth/authorize')">
<input type="hidden" v-for="([key, value]) in url.searchParams" :key="key" :name="key" :value="value" />
<div class="flex flex-col items-center gap-y-5">
<h1 class="font-bold text-2xl text-gray-50 text-center tracking-tight">Allow this application to
access your
account?</h1>
<div v-if="application" class="rounded-sm ring-2 ring-white/10 px-4 py-2 w-full">
<h2 class="font-bold text-gray-200">{{ application }}</h2>
<a v-if="website" :href="website" target="_blank" class="underline text-primary2-700">{{ website
}}</a>
</div>
</div>
<h2 class="text-gray-50 tracking-tight text-xl font-semibold">
This application will be able to:
</h2>
<ul class="flex flex-col gap-y-1.5">
<li v-for="text in getScopeText(scopes)" :key="text[1]" class="flex flex-row gap-1">
<svg class="fill-primary-600 w-5 h-5" xmlns="http://www.w3.org/2000/svg" fill="currentColor"
viewBox="0 0 16 16">
<path
d="M10.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L4.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093 3.473-4.425z" />
</svg>
<h2 class="text-sm text-gray-200">
<div class="flex h-svh items-center justify-center px-6 py-12 lg:px-8 bg-center bg-no-repeat bg-cover" :style="{
backgroundImage: 'url(/images/banner.webp)'
}">
<Card class="w-full max-w-md">
<CardHeader>
<CardTitle as="h1" class="text-2xl break-words">Authorize &ldquo;{{ application }}&rdquo;?</CardTitle>
</CardHeader>
<CardContent>
<Card>
<CardContent class="flex flex-col px-4 py-2">
<CardTitle as="h2" class="text-lg">{{ application }}</CardTitle>
<a v-if="website" :href="website" target="_blank" rel="noopener noreferrer" class="underline">{{ website }}</a>
</CardContent>
</Card>
<ul class="list-none my-6 [&>li]:mt-2">
<li v-for="text in getScopeText(scopes)" :key="text[1]" class="flex flex-row gap-1 items-center">
<Check class="size-4" />
<h2 class="text-sm">
<strong class="font-bold">{{ text[0] }}</strong> {{ text[1] }}
</h2>
</li>
</ul>
<div class="flex-col flex gap-y-1">
<p class="text-sm text-gray-200">You are signing in to <b>{{ application }}</b> with your
<div class="flex-col flex gap-y-1 text-sm">
<p>You are signing in to <b>{{ application }}</b> with your
account.</p>
<p class="text-sm text-gray-200">This allows <b>{{ application }}</b> to perform the above
<p>This allows <b>{{ application }}</b> to perform the above
account
actions.</p>
</div>
<div class="flex flex-col gap-3">
<Button theme="primary" type="submit">Authorize</Button>
<NuxtLink href="/" class="w-full">
<Button theme="secondary" class="w-full">Cancel</Button>
</NuxtLink>
</div>
</form>
</div>
<div v-else class="mx-auto max-w-md mt-10">
<h1 class="text-2xl font-bold tracking-tight text-gray-50 sm:text-4xl">Invalid access
parameters
</h1>
<p class="mt-6 text-lg leading-8 text-gray-300">This page should be accessed
through a valid OAuth2 authorization request. Please use a <strong class="font-bold">Mastodon
API</strong> client to access this page.
</p>
<p class="mt-6 text-lg leading-8 text-gray-300">Here are some recommended clients:</p>
<ul class="w-full flex flex-col gap-3 mt-4">
<li v-for="client of useConfig().RECOMMENDED_CLIENTS" :key="client.name" class="w-full">
<a :href="client.link" target="_blank"
class="rounded-sm ring-2 ring-white/10 px-4 py-2 w-full flex flex-row gap-3 items-center">
<img crossorigin="anonymous" :src="client.icon" :alt="`${client.name}'s logo'`"
class="h-10 w-10" />
<div class="flex flex-col justify-between items-start">
<h2 class="font-bold text-gray-100">{{ client.name }}</h2>
<span class="underline text-primary2-700">{{ client.link }}</span>
</div>
</a>
</li>
</ul>
<p class="mt-6 text-lg leading-8 text-gray-300">
Many other clients exist, but <strong class="font-bold">they have not been tested for
compatibility</strong>. Bug reports are nevertheless welcome.
</p>
<p class="mt-6 text-lg leading-8 text-gray-300">
Found a problem? Report it on <a href="https://github.com/versia-pub/server/issues/new/choose"
target="_blank" class="underline text-primary2-700">the issue tracker</a>.
</p>
</div>
</CardContent>
<CardFooter class="grid gap-2">
<Button variant="default" type="submit">Authorize</Button>
<Button :as="NuxtLink" href="/" variant="secondary">Cancel</Button>
</CardFooter>
</Card>
</div>
</template>
<script setup lang="ts">
import Button from "~/packages/ui/components/buttons/button.vue";
import { Check } from "lucide-vue-next";
import { Button } from "~/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card";
import { NuxtLink } from "#components";
const url = useRequestURL();
const params = useUrlSearchParams();

BIN
public/images/banner.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB