basic oauth flow

This commit is contained in:
Badtz 2025-03-31 18:57:32 -07:00
parent e53ebcfbfd
commit 4c14a1ce89
2 changed files with 33 additions and 0 deletions

6
src/lib/store.ts Normal file
View file

@ -0,0 +1,6 @@
import type { XRPC } from '@atcute/client';
import type { OAuthUserAgent } from '@atcute/oauth-browser-client';
import { writable, type Writable } from 'svelte/store';
export const rpc: Writable<XRPC | undefined> = writable(undefined);
export const agent: Writable<OAuthUserAgent | undefined> = writable(undefined);

View file

@ -0,0 +1,27 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { agent, rpc } from '$lib/store';
import { config } from '$lib/util';
import { XRPC } from '@atcute/client';
import { OAuthUserAgent, finalizeAuthorization } from '@atcute/oauth-browser-client';
import { onMount } from 'svelte';
onMount(async () => {
config();
const params = new URLSearchParams(location.hash.slice(1));
history.replaceState(null, '', location.pathname + location.search);
const session = await finalizeAuthorization(params);
const agentItem = new OAuthUserAgent(session);
const rpcItem = new XRPC({ handler: agentItem });
rpc.set(rpcItem);
agent.set(agentItem);
goto('/');
});
</script>
<h1>loading~</h1>