chadtmiller.com/monolith
An atproto PDS
0
0
<script lang="ts">
import Button from '#lib/atoms/Button.svelte';
import TechnicalDetails from '#lib/molecules/TechnicalDetails.svelte';
import PermissionList from '#lib/organisms/PermissionList.svelte';
import Request from '#lib/organisms/Request.svelte';
import Card from '#lib/templates/Card.svelte';
import { call, follow } from '#lib/api';
import { clientOf, type Account, type AuthorizeData } from '#lib/data';
import { detailsOf, rowsOf } from '#lib/scopes';
import { leaveAlert, words } from '#lib/words';
let {
data,
account,
token,
reached,
onchoose
}: {
data: AuthorizeData;
account: Account;
token?: string;
reached: boolean;
// Back, or Another account: Choose an account, signing nothing out.
onchoose: () => void;
} = $props();
const scope = $derived(data.scope ?? '');
let busy = $state<'allow' | 'deny' | null>(null);
let alert = $state('');
let ended = $state(false);
async function answer(endpoint: 'consent' | 'reject') {
busy = endpoint === 'consent' ? 'allow' : 'deny';
alert = '';
const a =
endpoint === 'consent'
? await call('consent', { did: account.did, scope: data.scope }, token)
: await call('reject', {}, token);
if (follow(a)) return;
busy = null;
alert = leaveAlert(a);
ended = a.status === 400;
}
</script>
<Card heading={words.allowAccess} {alert}>
<Request client={clientOf(data)} {account} />
<PermissionList
items={rowsOf(scope, data.permissionSets, { declarations: data.spaces, handles: data.spaceHandles })}
/>
<TechnicalDetails tokens={detailsOf(scope, data.permissionSets)} />
{#snippet actions()}
<Button
kind="primary"
label={words.allow}
busy={busy === 'allow'}
disabled={busy !== null || ended}
onclick={() => answer('consent')}
/>
<Button
label={words.deny}
busy={busy === 'deny'}
disabled={busy !== null || ended}
onclick={() => answer('reject')}
/>
{#if reached}
<Button label={words.back} icon="arrow-left" disabled={busy !== null} onclick={onchoose} />
{:else}
<Button
label={words.anotherAccount}
icon="person-add"
disabled={busy !== null || ended}
onclick={onchoose}
/>
{/if}
{/snippet}
</Card>