fix(docker): authenticate the dev app's MongoDB URI (MITHOME-98)

docker-compose.dev.yml's mongodb service sets MONGO_INITDB_ROOT_USERNAME/
PASSWORD, which makes the official mongo image enable --auth — but the
app service's MONGODB_URI was unauthenticated
(mongodb://mongodb:27017/mozdit). Same bug class as MITHOME-32
(staging/production), but that ticket covers docker-compose.staging.yml
/docker-compose.prod.yml specifically, not this dev file — hence the
separate MITHOME-98.

Why /api/health never caught it: that route is a pure liveness check
and never touches MongoDB. Only an endpoint that actually performs a
DB operation exercises the bug.

Verified live (docker compose -f docker-compose.dev.yml up --build):
- Reproduced the failure first: inside the running app container, a
  plain `mongodb://mongodb:27017/mozdit` connection's findOne() throws
  "Command find requires authentication" — confirms the hypothesis
  that the app fails only on a real query, not at startup.
- With the fix in place: POST /api/contact returns 200 with a
  submissionId, and the document is actually present in
  contact_submissions (checked via mongosh) — a real, previously-
  broken write path now works end to end.
- npm test: 58/58 passed (unaffected, as expected for a
  docker-compose/doc-only change).

Also fixed the same stale unauthenticated example in DOCKER.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-10 10:39:29 +02:00
co-authored by Claude Sonnet 5
parent 018a1f2767
commit 4c54c639e5
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ mongosh "mongodb://admin:password123@localhost:27017/mozdit"
### 3. Alkalmazásból
Az alkalmazás automatikusan csatlakozik:
```
MONGODB_URI=mongodb://mongodb:27017/mozdit
MONGODB_URI=mongodb://admin:password123@mongodb:27017/mozdit?authSource=admin
```
## 🛠️ Fejlesztési Parancsok
+5 -1
View File
@@ -12,7 +12,11 @@ services:
- "127.0.0.1:8080:3000"
environment:
- NODE_ENV=development
- MONGODB_URI=mongodb://mongodb:27017/mozdit
# WHY authSource=admin: the mongodb service below only creates a root
# user (via MONGO_INITDB_ROOT_USERNAME/PASSWORD), which forces --auth
# on the mongod process — an unauthenticated URI fails every query
# with "Command find requires authentication" (MITHOME-98).
- MONGODB_URI=mongodb://admin:password123@mongodb:27017/mozdit?authSource=admin
- MONGODB_DB=mozdit
- NEXT_PUBLIC_SITE_URL=http://localhost:8080
- NEXT_PUBLIC_COMPANY_NAME=mozdIT Bt.