Skip to content

Commit

Permalink
Prevent resubmission.
Browse files Browse the repository at this point in the history
  • Loading branch information
amyjko committed Jun 23, 2024
1 parent b296c15 commit 72d3c9b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/lib/NewOrganization.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down
16 changes: 13 additions & 3 deletions src/routes/login/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,30 @@
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;
else {
submitted = false;
message = null;
}
submitting = false;
}
$: if (browser && $user) goto(`/person/${$user.id}`);
Expand All @@ -55,8 +60,11 @@
bind:text={email}
invalid={(text) => (text.length === 0 || validEmail(email) ? undefined : 'Not a valid email')}
/>
<Button tip="Email the login code" active={validEmail(email)} action={sendCode} submit
>Send code …</Button
<Button
tip="Email the login code"
active={!submitting && validEmail(email)}
action={sendCode}
submit>Send code …</Button
>
</Form>
{:else}
Expand All @@ -69,7 +77,9 @@
invalid={(text) =>
text.length === 0 || text.length === 6 ? undefined : 'Codes are 6 characters'}
/>
<Button tip="Send login code" active={code.length === 6} action={login} submit>Login …</Button>
<Button tip="Send login code" active={!submitting && code.length === 6} action={login} submit
>Login …</Button
>
</Form>
{/if}

Expand Down

0 comments on commit 72d3c9b

Please sign in to comment.