diff --git a/js/app.js b/js/app.js index e6e8fff8..a7c7c678 100644 --- a/js/app.js +++ b/js/app.js @@ -1722,10 +1722,25 @@ class Application { "[app.js] loginNIP07 clicked! Attempting extension login..." ); try { - const { pubkey } = await this.authService.requestLogin(); + const { pubkey, detail } = await this.authService.requestLogin(); console.log("[NIP-07] login returned pubkey:", pubkey); if (pubkey) { + if ( + detail && + typeof detail === "object" && + detail.__handled !== true + ) { + try { + await this.handleAuthLogin(detail); + } catch (error) { + console.error( + "[NIP-07] handleAuthLogin fallback failed:", + error, + ); + } + } + const loginModal = document.getElementById("loginModal"); if (loginModal) { loginModal.classList.add("hidden"); @@ -2516,6 +2531,14 @@ class Application { } async handleAuthLogin(detail = {}) { + if (detail && typeof detail === "object") { + try { + detail.__handled = true; + } catch (error) { + // Ignore attempts to mutate read-only descriptors. + } + } + const normalizedActive = this.normalizeHexPubkey( detail?.pubkey || this.pubkey ); diff --git a/js/services/authService.js b/js/services/authService.js index 37589ec1..a185b10a 100644 --- a/js/services/authService.js +++ b/js/services/authService.js @@ -251,11 +251,11 @@ export default class AuthService { return { pubkey: trimmed }; } - await this.login(trimmed, { + const detail = await this.login(trimmed, { persistActive: options?.persistActive !== false, }); - return { pubkey: trimmed }; + return { pubkey: trimmed, detail }; } async handleUploadSubmit(payload, { publish } = {}) { @@ -372,6 +372,18 @@ export default class AuthService { postLogin, }; + try { + Object.defineProperty(detail, "__handled", { + configurable: true, + enumerable: false, + writable: true, + value: false, + }); + } catch (error) { + // Ignore descriptor errors (e.g., frozen objects) and fall back to direct assignment. + detail.__handled = false; + } + this.emit("auth:login", detail); return detail; }