Compare commits

...

2 Commits

Author SHA1 Message Date
Your Name
527e01b3e8 Got working with nostr-login 2025-08-18 13:59:12 -04:00
Your Name
86e403ab5f v2.2: Fix critical npub scope bug + relay update + enhanced debugging
- Fixed critical npub variable scope issue in submitAuthToBackend() that was causing 'Connecting...' hang
- Added relay.laantungir.net to NOSTR_RELAYS (first priority)
- Enhanced error handling with input validation and 30s timeout
- Added comprehensive debug logging for form submission
- Updated version displays to v2.2 throughout
- Improved error messages and user feedback
2025-08-18 12:51:10 -04:00
6 changed files with 63 additions and 49 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
nostr-login/

1
app.js
View File

@@ -19,6 +19,7 @@ const CLIENT_SECRET = 'gitea-secret';
// Nostr relays for fetching user metadata
const NOSTR_RELAYS = [
'wss://relay.laantungir.net',
'wss://relay.damus.io',
'wss://nos.lol',
'wss://relay.nostr.band',

1
nostr-login Submodule

Submodule nostr-login added at a679422d07

View File

@@ -2,9 +2,6 @@
"folders": [
{
"path": "."
},
{
"path": "../nostr-login"
}
],
"settings": {

4
upload.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
rsync -avz ./app.js ubuntu@laantungir.net:~/nostr-oidc-bridge/app.js
rsync -avz ./views/login.ejs ubuntu@laantungir.net:~/nostr-oidc-bridge/views/

View File

@@ -3,7 +3,13 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nostr Login - OIDC Bridge v2.1</title>
<title>OIDC Bridge v2.4</title>
<style>
body {
background: black
}
</style>
</head>
<body>
<div id="login-container">
@@ -19,22 +25,19 @@
</div>
<% } %>
<!-- Version header -->
<div style="text-align: center; margin: 10px 0; padding: 8px; background: #e3f2fd; border: 1px solid #2196f3; border-radius: 4px; font-weight: bold; color: #1976d2;">
🚀 Nostr OIDC Bridge v2.1 - Form Auth + event_json fix
</div>
<!-- Target div for nostr-login widget -->
<div id="nostr-login"></div>
<!-- Version info -->
<div style="position: fixed; bottom: 10px; right: 10px; font-size: 14px; color: #333; background: rgba(255,255,255,0.95); padding: 6px 12px; border-radius: 6px; border: 1px solid #ddd; font-weight: bold;">
v2.1 - Form Auth + event_json fix
</div>
</div>
<!-- Load your hosted nostr-login with full permissions -->
<script src='https://laantungir.net/nostr-login/unpkg.js'></script>
<!-- Load your hosted nostr-login with custom laan theme configuration -->
<script src='https://laantungir.net/nostr-login/unpkg.js'
data-theme='laan'
data-start-screen='welcome'
data-no-banner='true'></script>
<!-- Import nostr-tools for proper npub encoding -->
<script type="module">
@@ -46,35 +49,16 @@
<script>
let isProcessing = false;
// Initialize nostr-login widget
window.addEventListener('DOMContentLoaded', () => {
console.log('Initializing nostr-login widget...');
// Create nostr-login options
const nostrLoginOptions = {
bunkers: 'all',
methods: 'all',
noBanner: true,
startScreen: 'welcome-login',
theme: 'default'
};
console.log('nostr-login options', nostrLoginOptions);
// Initialize the widget
if (window.NostrLogin) {
window.NostrLogin.init(nostrLoginOptions);
} else {
console.error('NostrLogin not found on window object');
// Fallback: try to initialize after a delay
setTimeout(() => {
if (window.NostrLogin) {
console.log('Retrying NostrLogin initialization...');
window.NostrLogin.init(nostrLoginOptions);
}
}, 1000);
}
// Widget initialization is now handled automatically by the script data attributes
console.log('Nostr-login widget will initialize automatically with laan theme and immediate login display');
// Auto-launch the login modal immediately when page loads
window.addEventListener('load', () => {
// Small delay to ensure nostr-login widget is fully initialized
setTimeout(() => {
console.log('Auto-launching nostr-login modal...');
document.dispatchEvent(new CustomEvent('nlLaunch', { detail: 'login' }));
}, 100);
});
// Listen for nostr-login authentication events
@@ -144,7 +128,7 @@
}
// Submit to backend
await submitAuthToBackend(sessionId, pubkey, signedEvent);
await submitAuthToBackend(sessionId, pubkey, signedEvent, npub);
} catch (error) {
console.error('Authentication error:', error);
@@ -155,9 +139,24 @@
}
}
async function submitAuthToBackend(sessionId, pubkey, signedEvent) {
async function submitAuthToBackend(sessionId, pubkey, signedEvent, npub) {
try {
console.log('Submitting auth to backend...');
console.log('Submitting auth to backend...');
console.log('📋 Form data:', {
sessionId,
npub: npub ? `${npub.substring(0, 20)}... (length: ${npub.length})` : 'undefined',
pubkey: pubkey ? `${pubkey.substring(0, 20)}... (length: ${pubkey.length})` : 'undefined',
eventContent: signedEvent.content.substring(0, 20) + '...'
});
// Validate inputs before submission
if (!npub) {
throw new Error('npub is required but not provided');
}
if (!signedEvent || !signedEvent.sig) {
throw new Error('Valid signed event is required');
}
// Create a form and submit it traditionally to allow proper redirects
// This avoids CORS issues when redirecting to external domains like Gitea
@@ -169,7 +168,7 @@
const npubField = document.createElement('input');
npubField.type = 'hidden';
npubField.name = 'npub';
npubField.value = npub; // Use the properly encoded npub
npubField.value = npub;
form.appendChild(npubField);
const eventField = document.createElement('input');
@@ -180,11 +179,22 @@
// Add form to document and submit
document.body.appendChild(form);
console.log('Submitting form for authentication...');
console.log('🚀 Submitting form for authentication...');
// Add timeout to prevent infinite waiting
setTimeout(() => {
if (isProcessing) {
console.warn('⚠️ Form submission timeout - authentication may have failed');
showError('Authentication timed out. Please try again.');
isProcessing = false;
document.body.removeChild(form);
}
}, 30000); // 30 second timeout
form.submit();
} catch (error) {
console.error('Backend submission error:', error);
console.error('Backend submission error:', error);
throw error;
}
}