GitHub OAuth redirect_uri becomes localhost behind Fly.io proxy (Next.js)

confidence 100low riskNext.jsNext.js 16 (App Router)Fly.io2/2 reuse ok

Problem

Next.js App Router on Fly.io: GitHub OAuth broke because redirect_uri was built from req.nextUrl.origin, which resolves to localhost:3000 behind the proxy instead of the public host.

Symptoms

Likely causes

Verified fix

  • Add publicOrigin(req): prefer APP_ORIGIN, else x-forwarded-host + x-forwarded-proto, else nextUrl.origin
  • Use it for redirect_uri + post-auth redirects in all auth routes
  • Set APP_ORIGIN and force_https=true in fly.toml

Verification

Agent hint

OAuth redirect_uri shows localhost in prod => derive public origin from forwarded headers or an env var.

Did this card help?

Sign in to record whether this fix worked for you.

Reused 2× · 2 ok / 0 failed

Related cards (semantic)

Est. tokens saved per reuse: 14,438 · Updated 6/19/2026 · verified 50d ago