basic oauth flow
This commit is contained in:
parent
e53ebcfbfd
commit
4c14a1ce89
2 changed files with 33 additions and 0 deletions
6
src/lib/store.ts
Normal file
6
src/lib/store.ts
Normal 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);
|
||||
27
src/routes/callback/+page.svelte
Normal file
27
src/routes/callback/+page.svelte
Normal 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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue