From 734a708ac0e2b989a576edfcacd329720cbad4bb Mon Sep 17 00:00:00 2001 From: weebao Date: Sun, 24 Aug 2025 20:02:59 +0000 Subject: [PATCH 1/5] Fix infinite loading bug in Google OAuth callback form - Scout jam: [74c93e4f-3ac1-4a42-917c-e211ec198b0c](https://scout.new/jam/74c93e4f-3ac1-4a42-917c-e211ec198b0c) Co-authored-by: Scout --- docs/changes.md | 10 +++ .../login/google/callback/+page.server.ts | 15 +++- .../(auth)/login/google/callback/+page.svelte | 86 ++++++++++--------- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index 4d5989e..c613517 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,16 @@ Keep up with the latest updates here :D +## 2025-08-24 + +### Fixed + +- Fixed infinite loading bug when saving profile on Google OAuth callback page with existing username ([#TBD](https://github.com/beatcode-official/client/pull/TBD)) +- Added proper field-specific error messages for Google OAuth registration form +- Implemented consistent error handling patterns across authentication forms + +--- + ## 2025-04-30 ## Fixed diff --git a/src/routes/(auth)/login/google/callback/+page.server.ts b/src/routes/(auth)/login/google/callback/+page.server.ts index 48efebb..c803280 100644 --- a/src/routes/(auth)/login/google/callback/+page.server.ts +++ b/src/routes/(auth)/login/google/callback/+page.server.ts @@ -47,16 +47,25 @@ export const actions = { try { const response = await registerWithGoogle(form.data, cookies); + if (response.status === 400) { + const message: string = response.error.detail; + if (message.toLowerCase().includes("username")) { + form.errors.username = [message]; + } else if (message.toLowerCase().includes("email")) { + form.errors.email = [message]; + } + return fail(400, { form, message }); + } if (response.status >= 400) { - return fail(response.status, { form, error: response.error.detail }); + return fail(response.status, { form, message: response.error.detail }); } redirect(302, "/"); } catch (e: unknown) { if (isRedirect(e)) throw e; if (isHttpError(e)) { - return fail(e.status, { form, error: "Something went wrong in the server" }); + return fail(e.status, { form, message: "Something went wrong in the server" }); } - return fail(500, { form, error: "An unexpected error occurred" }); + return fail(500, { form, message: "An unexpected error occurred" }); } } }; diff --git a/src/routes/(auth)/login/google/callback/+page.svelte b/src/routes/(auth)/login/google/callback/+page.svelte index f7c615d..33c9cab 100644 --- a/src/routes/(auth)/login/google/callback/+page.svelte +++ b/src/routes/(auth)/login/google/callback/+page.svelte @@ -15,22 +15,28 @@ import { announce } from "$lib/utils"; import { onMount } from "svelte"; - import { fromStore } from "svelte/store"; let { data }: PageProps = $props(); - let registerForm = $state(); - let isSubmitting = $state(false); + let form = $state(); + let formData = $state(); + let submitting = $state(); + let enhance = $state(); onMount(() => { if (data.status === "success" && data.form) { - registerForm = superForm>(data.form, { + const registerForm = superForm>(data.form, { onResult: async ({ result }) => { if (result.type === "redirect") { announce(result, "Account created successfully"); } } }); + form = registerForm; + const { form: fd, submitting: sub, enhance: enh } = registerForm; + formData = fd; + submitting = sub; + enhance = enh; } }); @@ -55,62 +61,64 @@ - {#if registerForm} - {@const { enhance } = registerForm} - {@const registerFormData = fromStore( - registerForm.form - ).current} -
(isSubmitting = true)}> + {#if form && formData} +
- + - + {#snippet children({ props })} + + {/snippet} - + - + {#snippet children({ props })} + + {/snippet} - + - + {#snippet children({ props })} + + {/snippet} - + -
- + {#if form && formData}