Premiere brique de l'app d'admin independante : une surface /admin/*
ajoutee a apps/api, avec une authentification totalement distincte de
celle des utilisateurs.
- Table AdminUser isolee (aucune relation vers UserProfile), migration
20260828120000_admin_user.
- lib/admin-jwt.ts : sign/verify d'un JWT admin, secret ADMIN_JWT_SECRET
propre (jamais interchangeable avec JWT_SECRET).
- middlewares/require-admin.ts : cookie admin_session dedie, re-check
tokenVersion, echoue ferme si ADMIN_JWT_SECRET absent (posture
requireInternalWorker). res.locals.adminUser type via AdminLocals.
- modules/admin/ : admin-auth.{routes,service}.ts (POST /login, POST
/logout, GET /me), admin.routes.ts agregateur monte /admin. Pas de
signup expose.
- lib/safe-admin.ts : mapping AdminUser -> AdminUserView (drop passwordHash
+ tokenVersion, dates ISO).
- scripts/create-admin.ts : creation du 1er admin hors-bande (flags ou
ADMIN_INITIAL_*).
- CORS : setupCore accepte string[] ; app.ts autorise CORS_ORIGIN +
ADMIN_CORS_ORIGIN.
- Shared : schemas/admin.ts (adminLoginSchema), types/admin.ts
(AdminUserView).
- Env : ADMIN_JWT_SECRET (optionnel), ADMIN_COOKIE_NAME, ADMIN_CORS_ORIGIN,
ADMIN_INITIAL_* ; .env.example, .env.test.example, docker-compose.yml,
ci.yml mis a jour.
- reset-db.ts truncate admin_users.
- Tests Mocha admin-auth.test.ts : 400 sans body, 401 email inconnu /
mauvais mdp, login OK (cookie pose, lastLoginAt, pas de hash/tokenVersion
dans la reponse), /me derriere requireAdmin, logout, et un cookie
`session` d'utilisateur normal ne donne pas acces a /admin/*.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
64 lines
3.2 KiB
Text
64 lines
3.2 KiB
Text
# Used by docker-compose.yml to provision the local Postgres container.
|
|
# Pick your own values — do not reuse these across environments, and never
|
|
# commit the real .env (it's git-ignored).
|
|
POSTGRES_USER=changeme
|
|
POSTGRES_PASSWORD=changeme
|
|
POSTGRES_DB=batchcooking
|
|
POSTGRES_PORT=5432
|
|
|
|
# Used by docker-compose.yml's "app" service (Docker-only — the native
|
|
# `pnpm dev:api` workflow reads apps/api/.env instead, set both when using
|
|
# both workflows). Required, no default on purpose — generate your own.
|
|
JWT_SECRET=changeme-generate-a-real-random-secret-at-least-32-chars
|
|
|
|
# Optional — host port for the Docker review stack's single app container
|
|
# (docker-compose.yml), serving both the API and the built frontend.
|
|
# APP_PORT=3000
|
|
|
|
# --- Admin application (apps/admin-web + the /admin/* API surface) ---------
|
|
# All optional: an instance that doesn't run the admin app needs none of
|
|
# these. `requireAdmin` fails closed when ADMIN_JWT_SECRET is unset, so
|
|
# leaving it out simply disables every /admin/* route.
|
|
#
|
|
# Secret for the admin session JWT — MUST be different from JWT_SECRET so an
|
|
# end-user token can never be replayed against /admin/*. Generate your own
|
|
# the same way as JWT_SECRET above.
|
|
# ADMIN_JWT_SECRET=changeme-generate-a-real-random-secret-at-least-32-chars
|
|
# Origin apps/admin-web is served from, added to the CORS allow-list.
|
|
# ADMIN_CORS_ORIGIN=http://localhost:5174
|
|
# Host port for the Docker `admin-web` service (static nginx serving the
|
|
# built admin frontend).
|
|
# ADMIN_WEB_PORT=3001
|
|
# Optional — read only by `src/scripts/create-admin.ts` when its --email /
|
|
# --password / --name flags are omitted (e.g. to bootstrap the first admin
|
|
# from inside the container). Never read by the running server.
|
|
# ADMIN_INITIAL_EMAIL=ops@example.com
|
|
# ADMIN_INITIAL_PASSWORD=changeme-at-least-8-chars
|
|
# ADMIN_INITIAL_NAME=Ops
|
|
|
|
# Optional — only set this to false if THIS deployment is served over
|
|
# plain HTTP (no TLS in front of it). Left unset, the session cookie
|
|
# requires HTTPS (Secure attribute) as it should for a real deployment;
|
|
# over plain HTTP a Secure cookie is silently never sent back by the
|
|
# browser, so login "succeeds" but every subsequent request 401s.
|
|
# COOKIE_SECURE=false
|
|
|
|
# Required — secret shared between "app" and "tech-step-intent-service"
|
|
# (docker-compose.yml, apps/api/src/config/env.ts). Unlike
|
|
# INTERNAL_WORKER_SECRET below, there's no "leave it unset" escape hatch:
|
|
# tech-step-intent-service is a core dependency, not an optional background
|
|
# job — without it, no recipe step can have its techniques detected at all.
|
|
# Generate your own the same way as JWT_SECRET above.
|
|
INTENT_SERVICE_SECRET=changeme-generate-a-real-random-secret-at-least-32-chars
|
|
|
|
# Only needed to run the optional `tech-step-llm-worker` service — shared
|
|
# between it and "app" (docker-compose.yml). Generate your own the same
|
|
# way as JWT_SECRET above; leave both this and the service commented
|
|
# out/unset to run without it.
|
|
# INTERNAL_WORKER_SECRET=changeme-generate-a-real-random-secret-at-least-32-chars
|
|
|
|
# Optional — cron expression (node-cron syntax) the worker wakes up on to
|
|
# run its audit/feedback-loop jobs. Default: weekly, Sunday 03:00 — a
|
|
# provisional floor, not a calibrated value (see
|
|
# services/tech-step-llm-worker/README.md).
|
|
# TECH_STEP_WORKER_CRON=0 3 * * 0
|