diff options
| author | Adam Soltys <[email protected]> | 2025-01-03 15:24:31 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-01-03 15:24:31 -0800 |
| commit | 50296ccde06dc7892b0c6bd1546030f495564b28 (patch) | |
| tree | 444e26008235c9a57ec2756d8b8fa60133d4e4a9 /src/routes/(static) | |
| parent | 1bfdc18184fd57b741f5ebdfb0e323747f4d06b0 (diff) | |
| download | coinos-ui-50296ccde06dc7892b0c6bd1546030f495564b28.tar.gz coinos-ui-50296ccde06dc7892b0c6bd1546030f495564b28.zip | |
nostr sign in
Diffstat (limited to 'src/routes/(static)')
| -rw-r--r-- | src/routes/(static)/login/+page.server.ts | 2 | ||||
| -rw-r--r-- | src/routes/(static)/login/+page.svelte | 62 |
2 files changed, 13 insertions, 51 deletions
diff --git a/src/routes/(static)/login/+page.server.ts b/src/routes/(static)/login/+page.server.ts index 975dab5d..6bf06ad2 100644 --- a/src/routes/(static)/login/+page.server.ts +++ b/src/routes/(static)/login/+page.server.ts @@ -1,6 +1,6 @@ +import { PUBLIC_COINOS_URL } from "$env/static/public"; import { fd, get, login } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { PUBLIC_COINOS_URL } from "$env/static/public"; export const load = async ({ parent }) => { const { user } = await parent(); diff --git a/src/routes/(static)/login/+page.svelte b/src/routes/(static)/login/+page.svelte index bfd30fe2..dec02b17 100644 --- a/src/routes/(static)/login/+page.svelte +++ b/src/routes/(static)/login/+page.svelte @@ -3,21 +3,22 @@ import handler from "$lib/handler"; import { onMount } from "svelte"; - import { applyAction, deserialize } from "$app/forms"; + import { deserialize } from "$app/forms"; import { tick } from "svelte"; import { fly } from "svelte/transition"; import { enhance } from "$app/forms"; + import Nostr from "$comp/Nostr.svelte"; import Pinpad from "$comp/Pinpad.svelte"; import PasswordInput from "$comp/PasswordInput.svelte"; - import { focus, fail } from "$lib/utils"; + import { wait, copy, focus, fail } from "$lib/utils"; import { password, pin, loginRedirect } from "$lib/store"; import { t } from "$lib/translations"; import { page } from "$app/stores"; import { invalidateAll } from "$app/navigation"; - let nostr = $state(); + let { data, form } = $props(); + onMount(() => { - if (browser && window.nostr) nostr = true; $pin = undefined; localStorage.clear(); sessionStorage.clear(); @@ -26,11 +27,10 @@ if (lang) document.cookie = `lang=${lang} ;`; }); - let { data, form } = $props(); let { id } = $derived(data); + let nostrSignin = $state(); let token = $state(""); - let code = []; $password = undefined; @@ -78,43 +78,6 @@ }); }); - let nostrLogin = async () => { - let pubkey = await window.nostr.getPublicKey(); - const formData = new FormData(); - - let ev = { - kind: 1, - pubkey, - created_at: Date.now(), - content: id, - tags: [], - }; - - try { - let signedEvent = await window.nostr.signEvent(ev); - - formData.append("loginRedirect", redirect); - formData.append("token", token); - formData.append("event", JSON.stringify(signedEvent)); - formData.append("id", id); - - let response = await fetch("?/nostr", { - method: "POST", - body: formData, - }); - - const result = deserialize(await response.text()); - - if (result.type === "success") { - await invalidateAll(); - } - - applyAction(result); - } catch (e) { - fail(e.message); - } - }; - let redirect = $derived( $loginRedirect || $page.url.searchParams.get("redirect"), ); @@ -163,13 +126,10 @@ {$t("login.signIn")} </button> - {#if nostr} - <button type="button" class="btn" onclick={nostrLogin}> - <img src="/images/nostr.png" class="w-8" /> - <div class="my-auto">{$t("login.nostr")}</div> - </button> - {/if} - + <button type="button" class="btn" onclick={() => (nostrSignin = true)}> + <img src="/images/nostr.png" class="w-8" /> + <div class="my-auto">{$t("login.nostr")}</div> + </button> <p class="text-secondary text-center font-medium"> {$t("login.noAccount")} <a @@ -203,3 +163,5 @@ </div> </div> {/if} + +<Nostr {id} {nostrSignin} {redirect} {token} /> |
