From 72d3c9b0a5ea9560f403288e5f936365aef8bd63 Mon Sep 17 00:00:00 2001 From: "Amy J. Ko" Date: Sun, 23 Jun 2024 11:37:41 -0700 Subject: [PATCH] Prevent resubmission. --- src/lib/NewOrganization.svelte | 17 +++++++++++++---- src/routes/login/+page.svelte | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/lib/NewOrganization.svelte b/src/lib/NewOrganization.svelte index 646fda7..8f980f1 100644 --- a/src/lib/NewOrganization.svelte +++ b/src/lib/NewOrganization.svelte @@ -16,11 +16,20 @@ if ($user === null || $user.email === undefined) return; submitting = false; - const id = await $db.createOrganization(orgName, name, invite, $user.id, $user.email); + try { + const id = await $db.createOrganization(orgName, name, invite, $user.id, $user.email); - if (typeof id === 'string') goto(`/org/${id}`); - else - addError(errors, "Couldn't create a new organization with this invite code", id ?? undefined); + if (typeof id === 'string') goto(`/org/${id}`); + else + addError( + errors, + "Couldn't create a new organization with this invite code", + id ?? undefined + ); + } catch (e) { + console.log(e); + addError(errors, "Couldn't create a new organization", undefined); + } } let name = ''; diff --git a/src/routes/login/+page.svelte b/src/routes/login/+page.svelte index 689d7b1..6c8400b 100644 --- a/src/routes/login/+page.svelte +++ b/src/routes/login/+page.svelte @@ -19,18 +19,22 @@ let message: string | null = null; /** True if waiting for a code */ let submitted = false; + let submitting = false; let user = getUser(); async function sendCode() { + submitting = true; const { error } = await supabase.auth.signInWithOtp({ email }); if (error) message = error.code ?? error.message; else submitted = true; + submitting = false; } async function login() { + submitting = true; const { error } = await supabase.auth.verifyOtp({ email, token: code, type: 'email' }); if (error) message = error.code ?? error.message; @@ -38,6 +42,7 @@ submitted = false; message = null; } + submitting = false; } $: if (browser && $user) goto(`/person/${$user.id}`); @@ -55,8 +60,11 @@ bind:text={email} invalid={(text) => (text.length === 0 || validEmail(email) ? undefined : 'Not a valid email')} /> - Send code … {:else} @@ -69,7 +77,9 @@ invalid={(text) => text.length === 0 || text.length === 6 ? undefined : 'Codes are 6 characters'} /> - + {/if}