From 10afbd9777a47a0f339da7acc833acb85bad6aae Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Tue, 23 May 2023 10:17:15 -0700 Subject: [PATCH] Update the OAuth2 success and failure pages 1. Update design to be more consistent with other pages, while still unbranded 2. Update sizing to be more mobile friendly as the original heading size was truncated on mobile 3. Show a different message when redirecting back to the app to clarify the login was successful 4. Close the window after redirecting so the user doesn't have to --- src/routes/auth/oauth2/failure/+page.svelte | 60 ++++++++++++++++----- src/routes/auth/oauth2/success/+page.svelte | 60 ++++++++++++++++----- 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/src/routes/auth/oauth2/failure/+page.svelte b/src/routes/auth/oauth2/failure/+page.svelte index 359c6ffdca..928ad82c4e 100644 --- a/src/routes/auth/oauth2/failure/+page.svelte +++ b/src/routes/auth/oauth2/failure/+page.svelte @@ -2,20 +2,56 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; import { Heading } from '$lib/components'; - import { onMount } from 'svelte'; - onMount(async () => { - const project = $page.url.searchParams.get('project'); - if (project) { - await goto(`appwrite-callback-${project}://${$page.url.search}`); + const project = $page.url.searchParams.get('project'); + const link = `appwrite-callback-${project}://${$page.url.search}`; + + const redirect = new Promise((resolve, reject) => { + if (!project) { + reject('no-project'); } + // this timeout is needed because goto does not + // throw an exception if the redirect does not work + setTimeout(() => reject('timeout'), 500); + // goto will resolve on successful redirect + goto(link).then(resolve); }); -Missing Redirect URL -

- Your OAuth login flow is missing a proper redirect URL. Please check the - OAuth docs - and send request for new session with a valid callback URL. -

+{#await redirect then} +
+
+ Login failed +

You will be automatically redirected back to your app shortly.

+

+ If you are not redirected, please click on the following + link. +

+
+
+{:catch} +
+
+ Missing Redirect URL +

+ Your OAuth login flow is missing a proper redirect URL. Please check the + OAuth docs + and send request for new session with a valid callback URL. +

+
+
+{/await} + + diff --git a/src/routes/auth/oauth2/success/+page.svelte b/src/routes/auth/oauth2/success/+page.svelte index 359c6ffdca..b67ad0ce6f 100644 --- a/src/routes/auth/oauth2/success/+page.svelte +++ b/src/routes/auth/oauth2/success/+page.svelte @@ -2,20 +2,56 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; import { Heading } from '$lib/components'; - import { onMount } from 'svelte'; - onMount(async () => { - const project = $page.url.searchParams.get('project'); - if (project) { - await goto(`appwrite-callback-${project}://${$page.url.search}`); + const project = $page.url.searchParams.get('project'); + const link = `appwrite-callback-${project}://${$page.url.search}`; + + const redirect = new Promise((resolve, reject) => { + if (!project) { + reject('no-project'); } + // this timeout is needed because goto does not + // throw an exception if the redirect does not work + setTimeout(() => reject('timeout'), 500); + // goto will resolve on successful redirect + goto(link).then(resolve); }); -Missing Redirect URL -

- Your OAuth login flow is missing a proper redirect URL. Please check the - OAuth docs - and send request for new session with a valid callback URL. -

+{#await redirect then} +
+
+ You're now logged in +

You will be automatically redirected back to your app shortly.

+

+ If you are not redirected, please click on the following + link. +

+
+
+{:catch} +
+
+ Missing Redirect URL +

+ Your OAuth login flow is missing a proper redirect URL. Please check the + OAuth docs + and send request for new session with a valid callback URL. +

+
+
+{/await} + +