This guide helps you diagnose and fix common issues when using the Nostr Auth Middleware.
- Common Issues
- Environment-Specific Issues
- Error Messages
- Configuration Problems
- Integration Issues
- Performance Optimization
- Debug Mode
Symptom:
- "Nostr extension not found" error
- Login button doesn't respond
Solution:
- Check if a Nostr extension is installed (nos2x, Alby, etc.)
- Verify the extension is enabled
- Try refreshing the page
- Check console for specific errors
Symptom:
- "Invalid signature" error after signing
- Authentication fails after challenge
Solution:
- Verify the private key configuration:
const nostrAuth = createNostrAuth({ privateKey: process.env.SERVER_PRIVATE_KEY // Must be hex format });
- Check event creation:
// Event should match this format const event = { kind: 22242, created_at: Math.floor(Date.now() / 1000), tags: [['challenge', challengeId]], content: `nostr:auth:${challengeId}` };
Symptom:
- Changes not reflecting immediately
- Need to manually restart server
Solution:
- Check
NODE_ENV
is set to 'development' - Verify TypeScript compilation:
# Rebuild TypeScript npm run build # Check for compilation errors npm run build -- --noEmit
- Check file permissions in development directories
Symptom:
- "Directory not found" errors
- Permission denied in local directories
Solution:
- Check local directory structure:
# Create required directories mkdir -p logs backups # Check permissions ls -la logs backups
- Verify current user has write permissions
Symptom:
- Test features not working
- Database connection issues in test mode
Solution:
- Verify test mode is enabled:
# .env TEST_MODE=true NODE_ENV=development
- Check in-memory database configuration
- Verify test data is being loaded
Symptom:
- "EACCES: permission denied" errors
- Cannot write to log files
- Backup creation fails
Solution:
-
Check service user and group:
# Show directory ownership ls -l /opt/nostr-platform/auth ls -l /var/log/nostr-platform/auth # Fix permissions if needed sudo chown -R nostr:nostr /opt/nostr-platform/auth sudo chmod 755 /opt/nostr-platform/auth
-
Verify process is running as correct user:
# Check process user ps aux | grep nostr-auth # Start with correct user sudo -u nostr ./scripts/startup.sh
Symptom:
- Service not starting
- PM2 process issues
- Unexpected shutdowns
Solution:
-
Check PM2 process status:
pm2 list pm2 show nostr-auth-middleware
-
Verify PM2 logs:
pm2 logs nostr-auth-middleware
-
Check system logs:
sudo journalctl -u nostr-auth-middleware
Symptom:
- Logs not rotating
- Disk space issues
- Missing log files
Solution:
-
Check log rotation configuration:
# View log files ls -l /var/log/nostr-platform/auth/ # Check disk space df -h /var/log # Manually rotate logs if needed ./scripts/shutdown.sh # Includes log rotation
-
Verify log permissions:
# Fix log directory permissions sudo chown -R nostr:nostr /var/log/nostr-platform/auth sudo chmod 755 /var/log/nostr-platform/auth
Symptom:
- Backups not created
- Old backups not cleaned
- Backup process fails
Solution:
-
Check backup directory:
ls -l /opt/backups/nostr-platform/auth/
-
Verify backup rotation:
# Check old backups find /opt/backups/nostr-platform/auth/ -type f -mtime +60 # Manually clean old backups find /opt/backups/nostr-platform/auth/ -type f -mtime +60 -delete
-
Test backup creation:
# Create manual backup ./scripts/deploy.sh --backup-only
Error:
Challenge expired or not found
Fix:
- Check
eventTimeoutMs
in configuration - Ensure client clock is synchronized
- Verify challenge handling:
const { event: challengeEvent, challengeId } = await requestChallenge(pubkey); // Sign immediately after receiving const signedEvent = await window.nostr.signEvent(event);
Error:
Failed to connect to database
Fix:
- Verify Supabase credentials
- Check network connectivity
- Ensure proper configuration:
const nostrAuth = createNostrAuth({ supabaseUrl: process.env.SUPABASE_URL, supabaseKey: process.env.SUPABASE_KEY });
Problem: Missing or incorrect environment variables
Solution:
-
Create
.env
file:SUPABASE_URL=your_url SUPABASE_KEY=your_key SERVER_PRIVATE_KEY=your_key JWT_SECRET=your_secret
-
Load variables:
import dotenv from 'dotenv'; dotenv.config();
Problem: Cross-origin requests failing
Solution:
-
Configure CORS properly:
const nostrAuth = createNostrAuth({ corsOrigins: ['https://your-frontend.com'] });
-
For development:
const nostrAuth = createNostrAuth({ corsOrigins: '*' // Only in development! });
Problem: Component not rendering or updating
Solution:
-
Check imports:
import { NostrLogin } from '@maiqr/nostr-auth-enroll/react';
-
Verify props:
<NostrLogin apiUrl="http://localhost:3000" onLoginSuccess={(token, profile) => { // Handle success }} onLoginError={(error) => { console.error('Login failed:', error); }} />
Problem: API calls failing after authentication
Solution:
- Check token handling:
// Create axios instance const api = axios.create({ baseURL: '/api', headers: { 'Authorization': `Bearer ${getToken()}` } }); // Add interceptor for token refresh api.interceptors.response.use( response => response, async error => { if (error.response.status === 401) { // Handle token refresh } return Promise.reject(error); } );
Problem: Authentication taking too long
Solution:
-
Optimize challenge timeout:
const nostrAuth = createNostrAuth({ eventTimeoutMs: 30000 // 30 seconds });
-
Use connection pooling:
const pool = new Pool({ max: 20, idleTimeoutMillis: 30000 });
Problem: High memory usage
Solution:
-
Clean up challenges:
// Automatically remove expired challenges setInterval(() => { cleanupChallenges(); }, 60000);
-
Implement caching:
const cache = new Map(); function getCachedProfile(pubkey) { if (cache.has(pubkey)) { return cache.get(pubkey); } // Fetch and cache }
Enable debug mode for detailed logging:
const nostrAuth = createNostrAuth({
debug: true,
logger: {
level: 'debug',
format: 'json'
}
});
View logs:
# Production
pm2 logs nostr-auth-middleware
# Development
npm run dev
If you're still experiencing issues:
- Check our GitHub Issues
- Join our Discord community
- Create a minimal reproduction of the issue
- Include relevant logs and error messages
Found a bug or want to contribute a fix? See our Contributing Guide.