diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/(static)/login/+page.svelte | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/routes/(static)/login/+page.svelte b/src/routes/(static)/login/+page.svelte index 199f3634..f3aa04ef 100644 --- a/src/routes/(static)/login/+page.svelte +++ b/src/routes/(static)/login/+page.svelte @@ -66,36 +66,24 @@ }); }); - async function handleSubmit(e) { - e.preventDefault(); - let data = new FormData(this); - let user = Object.fromEntries(data); - - for (let k in user) { - data.set(k, user[k]); - } - + const enhanceLogin = async ({ formData, cancel }) => { try { const recaptcha = await getRecaptchaToken(); - data.set("recaptcha", recaptcha); + formData.set("recaptcha", recaptcha); } catch (err) { fail(err.message || "captcha failed"); + cancel(); return; } - const response = await fetch("?/login", { - method: "POST", - body: data, - }); - - const result = deserialize(await response.text()); + return async ({ result }) => { + if (result.type === "success") { + await invalidateAll(); + } - if (result.type === "success") { - await invalidateAll(); - } - - applyAction(result); - } + applyAction(result); + }; + }; $effect(() => { token?.length === 6 && @@ -180,9 +168,8 @@ {/if} <form - use:enhance + use:enhance={enhanceLogin} class="space-y-5" - onsubmit={handleSubmit} method="POST" action="?/login" > |
