From b22c813f9fb3b4d69dade75d22e90e6779919f07 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 16 Feb 2026 20:56:39 -0800 Subject: nostr key derivation --- src/routes/(static)/login/+page.svelte | 10 +++++++ src/routes/(static)/register/+page.svelte | 47 +++++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 6 deletions(-) (limited to 'src/routes/(static)') diff --git a/src/routes/(static)/login/+page.svelte b/src/routes/(static)/login/+page.svelte index fc1a6921..2c4df81e 100644 --- a/src/routes/(static)/login/+page.svelte +++ b/src/routes/(static)/login/+page.svelte @@ -173,6 +173,16 @@ const result = deserialize(await response.text()); + if (result.type === "success" || result.type === "redirect") { + try { + const { deriveNostrEntropy } = await import("$lib/walletEntropy"); + await deriveNostrEntropy(); + } catch (e) { + console.log("Nostr entropy derivation failed", e); + } + await invalidateAll(); + } + applyAction(result); } catch (e: any) { fail(e.message); diff --git a/src/routes/(static)/register/+page.svelte b/src/routes/(static)/register/+page.svelte index 273d319a..858b9695 100644 --- a/src/routes/(static)/register/+page.svelte +++ b/src/routes/(static)/register/+page.svelte @@ -14,7 +14,7 @@ import Spinner from "$comp/Spinner.svelte"; import { focus, fail, versions, post } from "$lib/utils"; - import { registerPasskey } from "$lib/passkey"; + import { registerPasskey, loginWithPasskey } from "$lib/passkey"; import { rememberPrfKey, defaultRememberForMs } from "$lib/passwordCache"; import { avatar, signer, password, pin, loginRedirect } from "$lib/store"; import { t } from "$lib/translations"; @@ -171,6 +171,35 @@ await activateSession(prfKey); } else { + // Registration failed (e.g. username taken) — try passkey sign-in + try { + const { credential, challengeId, prfKey } = await loginWithPasskey(); + const loginData = new FormData(); + loginData.append("credential", JSON.stringify(credential)); + loginData.append("challengeId", challengeId); + loginData.append("loginRedirect", (redirect ?? "") as string); + + const loginResponse = await fetch("/login?/passkey", { + method: "POST", + body: loginData, + }); + + const loginResult = deserialize(await loginResponse.text()); + + if (loginResult.type === "success" || loginResult.type === "redirect") { + rememberPrfKey(prfKey, defaultRememberForMs); + await invalidateAll(); + applyAction(loginResult); + loading = false; + return; + } + } catch (e: any) { + if (e.name !== "NotAllowedError") { + console.log("Passkey login failed", e); + } + } + + // Passkey cancelled or failed — show original registration error applyAction(result); } @@ -233,7 +262,7 @@ needsPasskey = false; await activateSession(prfKey); } catch (e: any) { - fail("Passkey creation failed. Please try again."); + fail($t("login.passkeyCreationFailed")); } loading = false; } @@ -302,7 +331,13 @@ const result = deserialize(await response.text()); - if (result.type === "success") { + if (result.type === "success" || result.type === "redirect") { + try { + const { deriveNostrEntropy } = await import("$lib/walletEntropy"); + await deriveNostrEntropy(); + } catch (e) { + console.log("Nostr entropy derivation failed", e); + } await invalidateAll(); } @@ -329,7 +364,7 @@ {#if need2fa} - + {/if}
@@ -373,12 +408,12 @@ {#if needsPasskey}
-

Account created! You need to set up a passkey to continue.

+

{$t("login.accountCreatedNeedsPasskey")}

-- cgit v1.2.3