diff --git a/docs/changes.md b/docs/changes.md index 4d5989e..3440453 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,6 +2,14 @@ Keep up with the latest updates here :D +## 2025-08-24 + +### Fixed + +- Submit button no longer loads infinitely when signing in with an existing username through Google ([#107](https://github.com/beatcode-official/client/pull/107)) + +--- + ## 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..bef6830 100644 --- a/src/routes/(auth)/login/google/callback/+page.svelte +++ b/src/routes/(auth)/login/google/callback/+page.svelte @@ -2,7 +2,7 @@ import type { PageProps } from "./$types"; import { type Infer, superForm } from "sveltekit-superforms"; - import { type RegisterWithGoogleData, RegisterWithGoogleSchema } from "$models/auth"; + import { RegisterWithGoogleSchema } from "$models/auth"; import * as Card from "$components/ui/card"; import { Button } from "$components/ui/button"; @@ -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; } }); @@ -54,63 +60,61 @@ {/if} - - {#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} - - + + -