Fixed issue not recognizing browser extension
This commit is contained in:
@@ -104,6 +104,18 @@
|
||||
|
||||
}});
|
||||
|
||||
// Check for existing authentication state on page load
|
||||
const authState = getAuthState();
|
||||
if (authState && authState.method) {
|
||||
console.log('Found existing authentication:', authState.method);
|
||||
document.getElementById('status').textContent = `Authenticated with: ${authState.method}`;
|
||||
document.getElementById('test-section').style.display = 'block';
|
||||
|
||||
// Store some test data for encryption/decryption
|
||||
window.testCiphertext = null;
|
||||
window.testCiphertext44 = null;
|
||||
}
|
||||
|
||||
// Listen for authentication events
|
||||
window.addEventListener('nlMethodSelected', (event) => {
|
||||
console.log('User authenticated:', event.detail);
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.1.4
|
||||
0.1.5
|
||||
|
||||
831
lite/build.js
831
lite/build.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1131,7 +1131,6 @@ class Modal {
|
||||
}
|
||||
|
||||
_setAuthMethod(method, options = {}) {
|
||||
// SINGLE-EXTENSION ARCHITECTURE: Handle method switching
|
||||
console.log('Modal: _setAuthMethod called with:', method, options);
|
||||
|
||||
// CRITICAL: Never install facade for extension methods - leave window.nostr as the extension
|
||||
@@ -1154,46 +1153,57 @@ class Modal {
|
||||
return;
|
||||
}
|
||||
|
||||
// For non-extension methods, we need to ensure WindowNostr facade is available
|
||||
console.log('Modal: Non-extension method detected:', method);
|
||||
// FOR NON-EXTENSION METHODS: Force-install facade with resilience
|
||||
console.log('Modal: Non-extension method - FORCE-INSTALLING facade with resilience:', method);
|
||||
|
||||
// Check if we have a preserved extension but no WindowNostr facade installed
|
||||
const hasPreservedExtension = !!window.NOSTR_LOGIN_LITE?._instance?.preservedExtension;
|
||||
const hasWindowNostrFacade = window.nostr?.constructor?.name === 'WindowNostr';
|
||||
// Store the current extension if any (for potential restoration later)
|
||||
const currentExtension = (window.nostr?.constructor?.name !== 'WindowNostr') ? window.nostr : null;
|
||||
|
||||
console.log('Modal: Method switching check:');
|
||||
console.log(' method:', method);
|
||||
console.log(' hasPreservedExtension:', hasPreservedExtension);
|
||||
console.log(' hasWindowNostrFacade:', hasWindowNostrFacade);
|
||||
console.log(' current window.nostr constructor:', window.nostr?.constructor?.name);
|
||||
// Get NostrLite instance for facade operations
|
||||
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
||||
if (!nostrLiteInstance || typeof nostrLiteInstance._installFacade !== 'function') {
|
||||
console.error('Modal: Cannot access NostrLite instance or _installFacade method');
|
||||
// Fallback: emit event anyway
|
||||
const event = new CustomEvent('nlMethodSelected', {
|
||||
detail: { method, ...options }
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
this.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// If we have a preserved extension but no facade, install facade for method switching
|
||||
if (hasPreservedExtension && !hasWindowNostrFacade) {
|
||||
console.log('Modal: Installing WindowNostr facade for method switching (non-extension authentication)');
|
||||
// IMMEDIATE FACADE INSTALLATION
|
||||
console.log('Modal: Installing WindowNostr facade immediately for method:', method);
|
||||
const preservedExtension = nostrLiteInstance.preservedExtension || currentExtension;
|
||||
nostrLiteInstance._installFacade(preservedExtension, true);
|
||||
console.log('Modal: WindowNostr facade force-installed, current window.nostr:', window.nostr?.constructor?.name);
|
||||
|
||||
// DELAYED FACADE RESILIENCE - Reinstall after extension override attempts
|
||||
const forceReinstallFacade = () => {
|
||||
console.log('Modal: RESILIENCE CHECK - Current window.nostr after delay:', window.nostr?.constructor?.name);
|
||||
|
||||
// Get the NostrLite instance and install facade with preserved extension
|
||||
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
||||
if (nostrLiteInstance && typeof nostrLiteInstance._installFacade === 'function') {
|
||||
const preservedExtension = nostrLiteInstance.preservedExtension;
|
||||
console.log('Modal: Installing facade with preserved extension:', preservedExtension?.constructor?.name);
|
||||
// If facade was overridden by extension, reinstall it
|
||||
if (window.nostr?.constructor?.name !== 'WindowNostr') {
|
||||
console.log('Modal: FACADE OVERRIDDEN! Force-reinstalling WindowNostr facade for user choice:', method);
|
||||
nostrLiteInstance._installFacade(preservedExtension, true);
|
||||
console.log('Modal: Resilient facade force-reinstall complete, window.nostr:', window.nostr?.constructor?.name);
|
||||
|
||||
nostrLiteInstance._installFacade(preservedExtension);
|
||||
console.log('Modal: WindowNostr facade installed for method switching');
|
||||
// Schedule another check in case of persistent extension override
|
||||
setTimeout(() => {
|
||||
if (window.nostr?.constructor?.name !== 'WindowNostr') {
|
||||
console.log('Modal: PERSISTENT OVERRIDE! Final facade force-reinstall for method:', method);
|
||||
nostrLiteInstance._installFacade(preservedExtension, true);
|
||||
}
|
||||
}, 1000);
|
||||
} else {
|
||||
console.error('Modal: Cannot access NostrLite instance or _installFacade method');
|
||||
console.log('Modal: Facade persistence verified - no override detected');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// If no extension at all, ensure facade is installed for local/NIP-46/readonly methods
|
||||
else if (!hasPreservedExtension && !hasWindowNostrFacade) {
|
||||
console.log('Modal: Installing WindowNostr facade for non-extension methods (no extension detected)');
|
||||
|
||||
const nostrLiteInstance = window.NOSTR_LOGIN_LITE?._instance;
|
||||
if (nostrLiteInstance && typeof nostrLiteInstance._installFacade === 'function') {
|
||||
nostrLiteInstance._installFacade();
|
||||
console.log('Modal: WindowNostr facade installed for non-extension methods');
|
||||
}
|
||||
}
|
||||
// Schedule resilience checks at multiple intervals
|
||||
setTimeout(forceReinstallFacade, 100); // Quick check
|
||||
setTimeout(forceReinstallFacade, 500); // Main check
|
||||
setTimeout(forceReinstallFacade, 1500); // Final check
|
||||
|
||||
// Emit auth method selection
|
||||
const event = new CustomEvent('nlMethodSelected', {
|
||||
|
||||
Reference in New Issue
Block a user