diff options
| author | Adam Soltys <[email protected]> | 2023-01-03 00:22:30 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-01-05 07:41:32 -0800 |
| commit | a657fab89a7de41f0a33389023166a6f7af6dbe6 (patch) | |
| tree | 77a485e5539be24542b38de582338946d317a4ce /src/components | |
| parent | 9849f6c4431214665c47c43098d86112c93d8001 (diff) | |
| download | coinos-ui-a657fab89a7de41f0a33389023166a6f7af6dbe6.tar.gz coinos-ui-a657fab89a7de41f0a33389023166a6f7af6dbe6.zip | |
generate pubkey on register
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/RegisterOrLogin.svelte | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte index b2070e9c..cc23d8ad 100644 --- a/src/components/RegisterOrLogin.svelte +++ b/src/components/RegisterOrLogin.svelte @@ -1,15 +1,18 @@ <script> + import { applyAction, deserialize } from '$app/forms'; import { tick } from 'svelte'; import { Pincode, PincodeInput } from 'svelte-pincode'; import { fly } from 'svelte/transition'; import { enhance } from '$app/forms'; - import { Icon } from '$comp'; + import { Icon, Spinner } from '$comp'; import { focus } from '$lib/utils'; import { password } from '$lib/store'; import { t } from '$lib/translations'; import { page } from '$app/stores'; + import { generate } from '$lib/nostr'; + import { invalidateAll } from '$app/navigation'; - let token, tokenInput; + let token, tokenInput, formElement; let code = []; let redirect; @@ -32,6 +35,33 @@ register: '/register', signIn: '/login' }[pageID]; + + let loading; + async function handleSubmit(e) { + loading = true; + + let data = new FormData(this); + let user = Object.fromEntries(data); + await generate(user); + + for (let k in user) { + data.set(k, user[k]); + } + + const response = await fetch(action, { + method: 'POST', + body: data + }); + + const result = deserialize(await response.text()); + + if (result.type === 'success') { + await invalidateAll(); + } + + applyAction(result); + loading = false; + } </script> <div class="pt-10"> @@ -81,7 +111,7 @@ </div> {/if} - <form class="space-y-5" {action} method="POST" use:enhance> + <form class="space-y-5" on:submit|preventDefault={handleSubmit} method="POST"> <div> <label for="username" class="font-semibold">{$t('login.username')}</label> <input @@ -141,7 +171,13 @@ <button type="submit" class="bg-black text-white w-full rounded-2xl p-4 font-semibold hover:opacity-80" - >{$t('login.' + pageID)} + disabled={loading} + > + {#if loading} + <Spinner /> + {:else} + {$t('login.' + pageID)} + {/if} </button> </form> |
