diff options
feat: scope prompt
for a target="_blank"
| -rw-r--r-- | src/routes/scope-prompt/[scopes]/+server.ts | 21 | ||||
| -rw-r--r-- | src/routes/scope-prompt/ok/+page.svelte | 12 | ||||
| -rw-r--r-- | src/routes/scope-prompt/ok/if/[scopes]/+page.server.ts | 17 | ||||
| -rw-r--r-- | src/routes/scope-prompt/ok/if/[scopes]/+page.svelte | 9 |
4 files changed, 59 insertions, 0 deletions
diff --git a/src/routes/scope-prompt/[scopes]/+server.ts b/src/routes/scope-prompt/[scopes]/+server.ts new file mode 100644 index 0000000..f919b9c --- /dev/null +++ b/src/routes/scope-prompt/[scopes]/+server.ts @@ -0,0 +1,21 @@ +import { base } from '$app/paths'; +import { checkScope } from '$lib/auth'; +import { error, redirect } from '@sveltejs/kit'; + +export const GET = async (e) => { + const scopes = e.params.scopes + .split(' ') + .flatMap((v) => v.split(',')) + .flatMap((v) => v.split('+')) + .filter((v) => v); + if ( + checkScope( + await e.locals.auth(), + scopes, + true, + base + '/scope-prompt/ok/if/' + scopes.join(',') + ) + ) + throw redirect(303, base + '/scope-prompt/ok'); + else throw error(500, 'In server mode, this branch should be unreachable'); +}; diff --git a/src/routes/scope-prompt/ok/+page.svelte b/src/routes/scope-prompt/ok/+page.svelte new file mode 100644 index 0000000..e4322f5 --- /dev/null +++ b/src/routes/scope-prompt/ok/+page.svelte @@ -0,0 +1,12 @@ +<script lang="ts"> + import { onMount } from 'svelte'; + + onMount(() => { + try { + window.close(); + } catch (error) {} + }); +</script> + +<h2 class="text-xl">All Good</h2> +<p>You can now close this window.</p> diff --git a/src/routes/scope-prompt/ok/if/[scopes]/+page.server.ts b/src/routes/scope-prompt/ok/if/[scopes]/+page.server.ts new file mode 100644 index 0000000..485edf4 --- /dev/null +++ b/src/routes/scope-prompt/ok/if/[scopes]/+page.server.ts @@ -0,0 +1,17 @@ +import { checkScope } from '$lib/auth'; +import { redirect } from '@sveltejs/kit'; + +export const load = async (e) => { + const scopes = e.params.scopes + .split(' ') + .flatMap((v) => v.split(',')) + .flatMap((v) => v.split('+')) + .filter((v) => v); + const session = await e.locals.auth(); + const hasScopes: string[] = session.tokens.scope?.split(' ') ?? []; + if (checkScope(session, scopes, false)) throw redirect(303, '../..'); + else + return { + missingScopes: scopes.filter((scope) => !hasScopes.includes(scope)), + }; +}; diff --git a/src/routes/scope-prompt/ok/if/[scopes]/+page.svelte b/src/routes/scope-prompt/ok/if/[scopes]/+page.svelte new file mode 100644 index 0000000..379ef14 --- /dev/null +++ b/src/routes/scope-prompt/ok/if/[scopes]/+page.svelte @@ -0,0 +1,9 @@ +<script lang="ts"> + import { page } from '$app/state'; +</script> + +<h2 class="text-xl">Missing Scopes</h2> +<p> + We could not get the following scopes from your account: {page.data + .missingScopes} +</p> |