From 4687db084f624817be4b30284f8ea88200d00daa Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Wed, 29 Jan 2025 13:25:45 +0100 Subject: [PATCH] fix fcn request --- apps/login/.env.integration | 3 +-- apps/login/src/app/(login)/verify/page.tsx | 2 +- apps/login/src/lib/service.ts | 13 +++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/apps/login/.env.integration b/apps/login/.env.integration index 8c07ac37d3..90adb84eee 100644 --- a/apps/login/.env.integration +++ b/apps/login/.env.integration @@ -1,4 +1,3 @@ ZITADEL_API_URL=http://localhost:22222 EMAIL_VERIFICATION=true -DEBUG=true -NEXT_PUBLIC_BASE_PATH="/" \ No newline at end of file +DEBUG=true \ No newline at end of file diff --git a/apps/login/src/app/(login)/verify/page.tsx b/apps/login/src/app/(login)/verify/page.tsx index 09e4eaba19..833ed663df 100644 --- a/apps/login/src/app/(login)/verify/page.tsx +++ b/apps/login/src/app/(login)/verify/page.tsx @@ -80,7 +80,7 @@ export default async function Page(props: { searchParams: Promise }) { }); } - const userResponse = await getUserByID(userId); + const userResponse = await getUserByID({ serviceUrl, userId }); if (userResponse) { user = userResponse.user; if (user?.type.case === "human") { diff --git a/apps/login/src/lib/service.ts b/apps/login/src/lib/service.ts index dd261e0b22..f6c70c66d3 100644 --- a/apps/login/src/lib/service.ts +++ b/apps/login/src/lib/service.ts @@ -34,8 +34,12 @@ export async function createServiceForHost( token = process.env.ZITADEL_SERVICE_USER_TOKEN; } - if (!serviceUrl || !token) { - throw new Error("No instance url or token found"); + if (!serviceUrl) { + throw new Error("No instance url found"); + } + + if (!token) { + throw new Error("No token found"); } const transport = createServerTransport(token, { @@ -48,9 +52,10 @@ export async function createServiceForHost( export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): string { let instanceUrl: string = process.env.ZITADEL_API_URL; + const forwardedHost = headers.get("x-zitadel-forward-host"); // use the forwarded host if available (multitenant), otherwise fall back to the host of the deployment itself - if (headers.get("x-zitadel-forward-host")) { - instanceUrl = headers.get("x-zitadel-forward-host") as string; + if (forwardedHost) { + instanceUrl = forwardedHost; instanceUrl = instanceUrl.startsWith("https://") ? instanceUrl : `https://${instanceUrl}`;