johnandersen777.bsky.social/knotless
git that lives in your Atmosphere account
Forked from chadtmiller.com/knotless
0
0
<script lang="ts">
import type * as getViewer from '#lib/lexicons/dev/knotless/getViewer.ts';
import type { Answer } from '#lib/data.ts';
import Delegate from '#lib/molecules/Delegate.svelte';
/**
* What someone sees on every page when what they granted is older than
* what knotless asks for now: their login, or their grant to this
* server's gateway. Each is brought up again in a click, the login
* first, as delegating asks with it.
*/
let { viewer }: { viewer: Answer<typeof getViewer.main> | null } = $props();
let problem = $state('');
let busy = $state(false);
async function login() {
busy = true;
problem = '';
const back = `${location.pathname}${location.search}`;
const res = await fetch('/oauth/login', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ handle: viewer?.actor?.did, back })
}).catch(() => null);
const text = (await res?.text().catch(() => '')) ?? '';
if (res?.ok) {
location.assign(JSON.parse(text).url);
return;
}
problem = (res && res.status < 500 && text) || 'Logging in did not work. Try again.';
busy = false;
}
</script>
{#if viewer?.actor && viewer.reauth}
<div class="notice offer grant-note" role="status">
<p>knotless can do more now than when you logged in. Log in again to allow it.</p>
<button class="btn primary" type="button" disabled={busy} aria-busy={busy} onclick={login}
>{busy ? 'Logging in…' : 'Log in again'}</button
>
{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
</div>
{:else if viewer?.actor && viewer.redelegate}
<div class="notice offer grant-note" role="status">
<p>
knotless can do more now than when you delegated to this server. Delegate again to allow it.
</p>
<Delegate primary done={() => location.reload()} />
</div>
{/if}