fix: set BACKEND_URL on frontend so docker-compose auth proxy works#7
fix: set BACKEND_URL on frontend so docker-compose auth proxy works#7TPFLegionaire wants to merge 1 commit into
Conversation
The Next.js rewrite in frontend/next.config.ts is:
destination: `${process.env.BACKEND_URL || "http://localhost:3501"}/api/auth/:path*`
The localhost fallback is correct for native dev (running `bun dev`
directly on the host alongside the backend), but in docker compose
the frontend service's localhost resolves to itself — not to the
backend container — so /api/auth/* gets proxied to nothing useful
and Better Auth requests 404.
Set BACKEND_URL to the backend service hostname so the rewrite lands
on the right container. The Docker bridge already resolves "backend"
to the backend service.
Repro: `make dev`, open http://localhost:3500/auth/sign-up, submit.
Network tab: POST /api/auth/sign-up/email returns 404 (rewrite hits
frontend container's own port 3501, which isn't bound).
After: same flow returns 200 and the user is created.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
giaphutran12
left a comment
There was a problem hiding this comment.
Holding for launch safety. This old branch is merge-conflicting with latest main and only has CodeRabbit reported. Please rebase or merge current main and rerun the normal checks before this can land.
Problem
In
make dev, all Better Auth requests fail because the frontend's/api/auth/*rewrite has no way to reach the backend container.frontend/next.config.tshas:destination: `${process.env.BACKEND_URL || "http://localhost:3501"}/api/auth/:path*`The
localhostfallback is correct for native dev (runningbun devdirectly on the host alongside the backend on the same machine). But inside Docker, the frontend container'slocalhost:3501resolves to itself, not to the backend service. The frontend doesn't listen on 3501, so the rewrite 404s.Net effect: sign-up / sign-in / sessions all fail silently from a docker-compose-only environment.
Fix
Set
BACKEND_URL: http://backend:3501on the frontend service indocker-compose.dev.yml. The Docker bridge already resolvesbackendto the backend service container — no other change needed.One line.
Verification
Before:
POST /api/auth/sign-up/emailreturns 404.After: 200 + session cookie + user row in Postgres.