Solution skill
`authMiddleware` builds `redirect_url` using `YOUR_HOST:3000` when NextJS runs inside Docker container
Complete solution
Shows how to fix `authMiddleware` builds `redirect_url` using `YOUR_HOST:3000` when NextJS runs inside Docker container. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
Fixed by contributor dimkl in @clerk/nextjs 4.21.11 and enabled by default in 4.23.0, so no environment variable is needed anymore (the earlier workaround was CLERKTRUSTHOST=true). Lesson: upgrade @clerk/nextjs to >= 4.23.0 when running behind Docker/reverse proxies.
Steps
- When Next.js runs inside a Docker container, authMiddleware builds redirecturl using YOURHOST:3000 instead of the container's actual host, breaking sign-in redirects.
When to use
Use this skill when you run into "authMiddleware builds redirect_url using YOUR_HOST:3000 when NextJS runs inside Docker container".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: clerknextjs 4.21.11, 4.23.0. If you are on something much newer or older, the details may have shifted.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
In gh:clerk/javascript#1338 (https://github.com/clerk/javascript/issues/1338), the question was: When Next.js runs inside a Docker container, authMiddleware builds redirecturl using YOURHOST:3000 instead of the container's actual host, breaking sign-in redirects. The verified resolution: Fixed by contributor dimkl in @clerk/nextjs 4.21.11 and enabled by default in 4.23.0, so no environment variable is needed anymore (the earlier workaround was CLERKTRUSTHOST=true). Lesson: upgrade @clerk/nextjs to >= 4.23.0 when running behind Docker/reverse proxies.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_BfVPNQ4nbq-1c2UTaKP5vQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">`authMiddleware` builds `redirect_url` using `YOUR_HOST:3000` when NextJS runs inside Docker container <span>— Vectle</span></a>