diff --git a/js/app.js b/js/app.js index ad54ecbd..df2a9db0 100644 --- a/js/app.js +++ b/js/app.js @@ -3038,7 +3038,19 @@ class Application { } isUserLoggedIn() { - return Boolean(this.normalizeHexPubkey(this.pubkey)); + const normalizedPubkey = this.normalizeHexPubkey(this.pubkey); + if (!normalizedPubkey) { + return false; + } + + const sessionActorPubkey = this.normalizeHexPubkey( + nostrClient?.sessionActor?.pubkey, + ); + if (sessionActorPubkey && sessionActorPubkey === normalizedPubkey) { + return false; + } + + return true; } async updateActiveNwcSettings(partial = {}) { diff --git a/tests/video-modal-zap.test.mjs b/tests/video-modal-zap.test.mjs index 96e6bcd6..e259bf5c 100644 --- a/tests/video-modal-zap.test.mjs +++ b/tests/video-modal-zap.test.mjs @@ -182,7 +182,16 @@ function createVideoModalStub() { return { setCopyEnabled: noop, setShareEnabled: noop, - setZapVisibility: noop, + setWalletPromptVisible: noop, + zapVisibilityCalls: [], + setZapVisibility(config) { + const payload = + config && typeof config === "object" + ? { ...config } + : { visible: Boolean(config) }; + this.zapVisibilityCalls.push(payload); + this.lastZapVisibility = payload; + }, dialogOpen: false, closeZapDialogCalls: [], closeZapDialog(options = {}) { @@ -349,6 +358,40 @@ await (async () => { app.destroy(); })(); +await (async () => { + // Test: session actors should not be treated as logged-in users for zaps + const { app, modalStub } = await createApp({ + splitAndZap: async () => ({ receipts: [] }), + }); + + const { nostrClient } = await import("../js/nostr.js"); + const originalSessionActor = nostrClient.sessionActor; + const sessionPubkey = "a".repeat(64); + nostrClient.sessionActor = { pubkey: sessionPubkey, privateKey: "priv" }; + + app.pubkey = sessionPubkey; + + modalStub.zapVisibilityCalls = []; + app.zapController.setVisibility(true); + + const lastVisibility = + modalStub.zapVisibilityCalls[modalStub.zapVisibilityCalls.length - 1]; + assert.deepEqual( + lastVisibility, + { visible: true, requiresLogin: true }, + "zap controller should require login when only a session actor is present", + ); + assert.equal( + app.isUserLoggedIn(), + false, + "session actor pubkeys should not count as logged-in users", + ); + + app.pubkey = null; + nostrClient.sessionActor = originalSessionActor; + app.destroy(); +})(); + await (async () => { // Test: wallet required before zapping const splitCalls = [];