Repository navigation
Pass the Keycloak client ID to next build (WEB-031) - #266
Merged
Merged
Conversation
The ban-appeal login failed after sign-in: the browser asked Keycloak for a code as the "website" client, but TripBot redeems it as the ban-appeals client, and Keycloak binds a code to the client that requested it. Next.js writes NEXT_PUBLIC_* values into the browser bundle during next build. The Dockerfile never declared them, so the build saw none and the bundle always fell back to "website". Declare NEXT_PUBLIC_DNS_DOMAIN, NEXT_PUBLIC_KEYCLOAK_URL and NEXT_PUBLIC_KEYCLOAK_CLIENT_ID as ARG/ENV in the build stage so compose build.args reach it. keycloak.ts said its config was read "at runtime instead of build time", which is wrong for client code; the comment now says how it works. The "website" fallback is gone: a missing client ID throws outside production, and in production it is logged and Keycloak rejects the request before the user signs in, instead of TripBot failing afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Ban-appeal login at
/appealfails after the user signs in. TripBot logs "Keycloak token error" andPOST /api/v2/keycloak/tokenreturns 500.Keycloak binds an auth code to the client that requested it. TripBot redeems the code as the ban-appeals client (
KEYCLOAK_BAN_APPEALS_CLIENT_ID). The browser asked for the code aswebsite.Next.js writes
NEXT_PUBLIC_*values into the browser bundle duringnext build. The Dockerfile never declared them, sonext buildsaw none. The live bundle on tripsit.me still reads the value at runtime from the browser's emptyprocessshim, so it always uses the fallback:Changes
Dockerfile: thebuildstage declaresNEXT_PUBLIC_DNS_DOMAIN,NEXT_PUBLIC_KEYCLOAK_URLandNEXT_PUBLIC_KEYCLOAK_CLIENT_IDasARGandENVbeforeRUN npx next build, so composebuild.argsand--build-argreach the build. An unset arg becomes an empty string, and the code's||fallbacks still apply.src/utils/keycloak.ts: the comment said config is read "at runtime instead of build time". That's wrong for client code. It now explains that the values are fixed when the bundle is built.keycloak.ts): I removed the"website"fallback. That client is always wrong here, because TripBot redeems every code as the appeals client. I didn't hardcode the appeals client ID: this repo doesn't contain it, and the build arg is the source of truth.next dev, Jest): a missing client ID throws an error that names the variable.console.error, and the login URL gets an emptyclient_id. Keycloak then rejects the request before the user signs in, instead of TripBot failing afterwards with a 500.next builditself fail, because the GitHub Actions builds run without these variables.getPostLogoutUrl()doesn't need a client ID, so logout isn't affected.src/utils/__tests__/keycloak.test.tscovers the login URL, the URL override and both missing-ID cases..env.example: documentsNEXT_PUBLIC_KEYCLOAK_CLIENT_IDfor local development.REVIEW-ISSUES.md: adds WEB-031 for this bug and lists it in the Auth and Docker/Drone overlap groups.Needs changes outside this repo
.drone.ymlrunsdocker compose -f docker-compose.website-prod.yml, but that file isn't in this repo. It lives on the UAT server (see WEB-014), so I couldn't check or change it. Itsbuild:block needs:build.args, UAT builds this branch with an empty client ID: the browser console shows the missing-ID error, and Keycloak rejects the login. Before this change, UAT usedwebsiteinstead, which failed too.mainof this repo. The live compose change (build.argsindocker-compose.website.yml) does nothing until this commit is promoted fromuattomain.Verification
npm run lint: 0 errors. The 2 warnings were already there (WEB-025).npm test: 41 of 41 pass, including the 4 new tests.docker build --target production --build-arg NEXT_PUBLIC_KEYCLOAK_CLIENT_ID=placeholder-appeals-client .succeeds, includingnext build's TypeScript check./appeal's page chunk, next toopenid-connect/auth. It now readsclient_id:"placeholder-appeals-client"andurl:"https://auth.tripsit.me", both literals.env.NEXT_PUBLIC_, so nothing reads these values at runtime."website"no longer appears.GET /appealreturned 200, and the chunk the page loads contains the literal.console.error(...)branch and sends an emptyclient_id, notwebsite./appeal, because that needs a test account and a deployed build with the real client ID.🤖 Generated with Claude Code