From 0b5634a75ef39fcd697d49f1fc3166ba00e44b52 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Jan 2026 10:19:43 +0000 Subject: [PATCH] fix: establish WebSocket connection before showing QR code Fixes NIP-46 QR code login by opening the relay connections BEFORE displaying the QR code. This ensures the client is listening when the remote signer responds. Also adds console logging for debugging NIP-46 connection flow. --- src/components/nostr/LoginDialog.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/components/nostr/LoginDialog.tsx b/src/components/nostr/LoginDialog.tsx index 8cf6f48..c6dc1f8 100644 --- a/src/components/nostr/LoginDialog.tsx +++ b/src/components/nostr/LoginDialog.tsx @@ -175,11 +175,18 @@ export default function LoginDialog({ open, onOpenChange }: LoginDialogProps) { }); signerRef.current = signer; + // IMPORTANT: Open the connection FIRST before showing QR + // This ensures we're listening when the signer responds + await signer.open(); + // Generate the nostrconnect:// URI const uri = signer.getNostrConnectURI({ name: "Grimoire", url: window.location.origin, }); + + // Log for debugging + console.log("[NIP-46] Generated nostrconnect URI:", uri); setConnectUri(uri); // Generate QR code with extra margin for better scanning @@ -193,19 +200,19 @@ export default function LoginDialog({ open, onOpenChange }: LoginDialogProps) { }); setQrDataUrl(dataUrl); - // Open the signer to start listening - await signer.open(); - // Set up abort controller for cancellation abortControllerRef.current = new AbortController(); setLoading(false); // Wait for the remote signer to connect + console.log("[NIP-46] Waiting for remote signer..."); await signer.waitForSigner(abortControllerRef.current.signal); + console.log("[NIP-46] Remote signer connected!"); // Get the user's pubkey const pubkey = await signer.getPublicKey(); + console.log("[NIP-46] Got pubkey:", pubkey); const account = new NostrConnectAccount(pubkey, signer); handleSuccess(account);