Error: createAuthenticationMiddleware is not a function
This error occurred when starting claude-flow-ui with BACKSTAGE_REQUIRE_AUTH=true.
Problem: The TypeScript-to-JavaScript compilation didn't include the factory functions.
Fix: Added exports to src/middleware/authentication.js (lines 276-330):
exports.createAuthenticationMiddleware = createAuthenticationMiddleware;
exports.createWebSocketAuthHandler = createWebSocketAuthHandler;Problem: unified-server.js used url but services expected backstageUrl.
Fix: Updated unified-server.js (line 25-26) to include both:
backstageConfig = {
backstageUrl: process.env.BACKSTAGE_URL || null,
url: process.env.BACKSTAGE_URL || null, // Backward compatibility
// ... rest of config
}# Test module loads
node -e "const { createAuthenticationMiddleware, createWebSocketAuthHandler } = require('./src/middleware/authentication'); console.log('✅ Exports work');"Expected: ✅ Exports work
export BACKSTAGE_URL="https://backstage.example.com"
export BACKSTAGE_REQUIRE_AUTH="true"
node unified-server.jsExpected Console Output:
🔐 Backstage Authentication Configuration:
URL: https://backstage.example.com
...
🔒 Initializing Backstage authentication middleware...
✅ Backstage authentication middleware enabled
| File | Lines | Change |
|---|---|---|
src/middleware/authentication.js |
276-330 | Added factory function exports |
unified-server.js |
25-26 | Added backstageUrl to config |
Comprehensive testing guide: docs/BACKSTAGE_AUTH_TESTING.md
Quick test:
./test-auth-startup.sh✅ Server starts with authentication enabled ✅ API routes protected (return 401 without token) ✅ Frontend routes protected (return 401 without token) ✅ WebSocket connections protected (reject without token) ✅ Static assets still load (CSS/JS don't need auth) ✅ Environment variables supported for all options ✅ CLI arguments supported for all options
# Production setup
export BACKSTAGE_URL="https://backstage.company.com"
export BACKSTAGE_REQUIRE_AUTH="true"
export BACKSTAGE_ALLOWED_GROUPS="group:default/platform-team"
npx claude-flow-ui
# Or with CLI args
npx claude-flow-ui \
--backstage-url https://backstage.company.com \
--backstage-require-auth true \
--backstage-allowed-groups "group:default/platform-team"- Configuration:
docs/BACKSTAGE_AUTH_CONFIG.md - Testing:
docs/BACKSTAGE_AUTH_TESTING.md - Enforcement Details:
docs/BACKSTAGE_AUTH_ENFORCEMENT.md - Startup Fix Details:
docs/AUTHENTICATION_STARTUP_FIX.md - Quick Start:
docs/BACKSTAGE_AUTH_QUICK_START.md
- Start server with authentication enabled
- Verify 401 responses for unauthenticated requests
- Test with real Backstage JWT tokens
- Configure production settings
- Monitor audit logs