From 52bf618b51cf8a748cf7a092b0729eda64b243aa Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Thu, 9 Jul 2026 14:57:20 +0700 Subject: [PATCH] Fix amber login type: use x-amber instead of amber MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit NLoginOther requires type x-${string} to be a valid NLoginType. Using bare 'amber' meant pubkey was never properly stored/rehydrated from localStorage — it was always undefined/empty. Using NLogin('x-amber', pubkey, ...) correctly stores pubkey through the NLoginBase interface and survives localStorage serialization. Co-authored-by: shakespeare.diy --- src/hooks/useCurrentUser.ts | 2 +- src/hooks/useLoginActions.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/hooks/useCurrentUser.ts b/src/hooks/useCurrentUser.ts index 2e02170..ae900a5 100644 --- a/src/hooks/useCurrentUser.ts +++ b/src/hooks/useCurrentUser.ts @@ -22,7 +22,7 @@ export function useCurrentUser() { return NUser.fromBunkerLogin(login, nostr); case 'extension': // Nostr login with NIP-07 browser extension return NUser.fromExtensionLogin(login); - case 'amber': { // Nostr login with Amber (NIP-55) + case 'x-amber': { // Nostr login with Amber (NIP-55) const amberLogin = login as AmberLoginType; // On Capacitor (ZapStore APK) use the native plugin signer so all // signing operations go through Amber via native intents. diff --git a/src/hooks/useLoginActions.ts b/src/hooks/useLoginActions.ts index a781caf..c2e6757 100644 --- a/src/hooks/useLoginActions.ts +++ b/src/hooks/useLoginActions.ts @@ -7,7 +7,9 @@ import { // NOTE: This file should not be edited except for adding new login methods. -export type AmberLoginType = { id: string; type: 'amber'; pubkey: string }; +// NLoginOther requires type to be `x-${string}` — use x-amber so it +// is a valid NLoginType and pubkey is preserved through serialization. +export type AmberLoginType = NLoginType & { type: 'x-amber'; pubkey: string }; export function useLoginActions() { const { nostr } = useNostr(); @@ -34,15 +36,13 @@ export function useLoginActions() { const login = await NLogin.fromExtension(); addAndActivate(login); }, - // Login with Amber (NIP-55) — pubkey comes from the AmberCallbackPage + // Login with Amber (NIP-55) — pubkey returned from Amber plugin or callback + // Uses NLogin with type x-amber so it satisfies NLoginOther (x-${string}) + // and pubkey is correctly stored and rehydrated from localStorage. amber(pubkey: string): void { - const amberLogin: AmberLoginType = { - id: `amber:${pubkey}`, - type: 'amber', - pubkey, - }; - addLogin(amberLogin as unknown as NLoginType); - setLogin(amberLogin.id); + const login = new NLogin('x-amber', pubkey, { method: 'nip55' }) as unknown as NLoginType; + addLogin(login); + setLogin(login.id); }, // Log out the current user async logout(): Promise {