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:

  1. Hardcode tokens in scripts
  2. Fetch JWT from auth endpoint
  3. Use SYSTEM_TOKEN from env-loader.js
  4. 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


🔗 Related


Auto-generated by MCP Smart Consolidation