Pattern: How should Node.js scripts authenticate with backend APIs in...
Documentation for Sessions
🎨 Pattern: How should Node.js scripts authenticate with backend APIs in...
Date: 2026-01-22
Time: 19:22:26 UTC
Session: editor2-58.14
Agent: architecture
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
How should Node.js scripts authenticate with backend APIs in this monorepo?
Task: Establish authentication pattern for internal scripts
🎯 Decision Made
Chosen:
Use SYSTEM_TOKEN from env-loader.js
Options Considered:
- Hardcode tokens in scripts
- Fetch JWT from auth endpoint
- Use SYSTEM_TOKEN from env-loader.js
- Use API keys
💭 Reasoning
All backend APIs (backend-api, backend-ai-api, backend-docs-api) use the shared AuthCoreModule which accepts SYSTEM_TOKEN for internal automation. The pattern is: (1) Import getSystemToken from tools/scripts/database/env-loader.js; (2) Pass token as Bearer header; (3) JwtAuthGuard recognizes it and authenticates as system user. This avoids managing JWT expiration, refresh tokens, or separate auth flows for scripts. The SYSTEM_TOKEN is stored in .env.local (never committed) and read by env-loader.
📁 Files Involved
tools/scripts/database/env-loader.jslibs/libs-api/auth-core/src/lib/guards/jwt-auth.guard.ts.env.local
🔗 Related
- Decision ID:
dev_1769109746753_abxzg32 - Session: 58
- Workspace: editor2
Auto-generated by MCP Smart Consolidation