diff --git a/config/instance-config.js b/config/instance-config.js index a391e0a2..b79faf83 100644 --- a/config/instance-config.js +++ b/config/instance-config.js @@ -219,6 +219,15 @@ export const ADMIN_WHITELIST_MODE_STORAGE_KEY = "bitvid_admin_whitelist_mode"; */ export const DEFAULT_WHITELIST_MODE_ENABLED = true; +/** + * Whether bitvid should clear stored NIP-07 permissions when users log out. + * + * Set this to `true` if your environment requires removing cached extension + * permissions on logout (e.g., shared devices). Leave it `false` to preserve + * permissions so returning users do not need to reauthorize the extension. + */ +export const CLEAR_NIP07_PERMISSIONS_ON_LOGOUT = false; + /** * Whether the public client should display content flagged as NSFW. * diff --git a/js/config.js b/js/config.js index 73d5fe76..96f26c27 100644 --- a/js/config.js +++ b/js/config.js @@ -43,6 +43,7 @@ import { ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS, DEFAULT_PLAYBACK_SOURCE, DEFAULT_PLAYBACK_START_TIMEOUT, + CLEAR_NIP07_PERMISSIONS_ON_LOGOUT, } from "../config/instance-config.js"; export const WATCH_HISTORY_VERSION_TAG_VALUE = "2"; @@ -137,3 +138,4 @@ export { VIEW_COUNT_CACHE_TTL_MS }; export { ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS }; export { DEFAULT_PLAYBACK_SOURCE }; export { DEFAULT_PLAYBACK_START_TIMEOUT }; +export { CLEAR_NIP07_PERMISSIONS_ON_LOGOUT }; diff --git a/js/nostr/client.js b/js/nostr/client.js index c04641cf..ea45a1e3 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -17,7 +17,7 @@ * - Signer Management: Orchestrates NIP-07 (Extension), NIP-46 (Remote/Bunker), and NIP-01 (Local nsec) signers. */ -import { isDevMode } from "../config.js"; +import { CLEAR_NIP07_PERMISSIONS_ON_LOGOUT, isDevMode } from "../config.js"; import { FEATURE_PUBLISH_NIP71 } from "../constants.js"; import { bytesToHex, sha256 } from "../../vendor/crypto-helpers.bundle.min.js"; import { infoHashFromMagnet } from "../magnets.js"; @@ -4396,9 +4396,9 @@ export class NostrClient { * - Wipes session actor (ephemeral keys). * - Disconnects NIP-46 remote signer (if active). * - Clears Watch History cache. - * - Resets permissions cache. + * - Optionally clears stored NIP-07 permissions. */ - logout() { + logout({ clearNip07Permissions = null } = {}) { const previousPubkey = this.pubkey; this.pubkey = null; logoutSigner(previousPubkey); @@ -4432,13 +4432,20 @@ export class NostrClient { } this.watchHistory.clear(); - if ( - this.extensionPermissionCache && - typeof this.extensionPermissionCache.clear === "function" - ) { - this.extensionPermissionCache.clear(); + const shouldClearNip07Permissions = + typeof clearNip07Permissions === "boolean" + ? clearNip07Permissions + : CLEAR_NIP07_PERMISSIONS_ON_LOGOUT; + + if (shouldClearNip07Permissions) { + if ( + this.extensionPermissionCache && + typeof this.extensionPermissionCache.clear === "function" + ) { + this.extensionPermissionCache.clear(); + } + clearStoredNip07Permissions(); } - clearStoredNip07Permissions(); devLogger.log("User logged out."); }