Skip to content

Commit 744ca3b

Browse files
committed
fix: use server-side KEYCLOAK_URL for container-to-container JWT verification
In Docker, the frontend container's middleware resolves NEXT_PUBLIC_KEYCLOAK_URL (http://localhost:8080) to itself instead of the keycloak container, causing ECONNREFUSED. Prefer the runtime KEYCLOAK_URL env var (http://keycloak:8080) on the server side for proper Docker DNS resolution.
1 parent 4f07775 commit 744ca3b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/utils/authHelpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export const getKeycloakBaseUrl = () => {
4040

4141
// backend
4242
export function getKeycloakBaseFromHost(hostname: string | undefined): string {
43+
// Server-side: prefer KEYCLOAK_URL for container-to-container communication
44+
if (typeof window === 'undefined' && process.env.KEYCLOAK_URL) {
45+
return process.env.KEYCLOAK_URL
46+
}
47+
4348
if (
4449
process.env.NEXT_PUBLIC_KEYCLOAK_URL &&
4550
process.env.NEXT_PUBLIC_KEYCLOAK_URL.trim() !== ''

0 commit comments

Comments
 (0)