fix fcn request

This commit is contained in:
Max Peintner
2025-01-29 13:25:45 +01:00
parent f117044c53
commit 4687db084f
3 changed files with 11 additions and 7 deletions

View File

@@ -1,4 +1,3 @@
ZITADEL_API_URL=http://localhost:22222 ZITADEL_API_URL=http://localhost:22222
EMAIL_VERIFICATION=true EMAIL_VERIFICATION=true
DEBUG=true DEBUG=true
NEXT_PUBLIC_BASE_PATH="/"

View File

@@ -80,7 +80,7 @@ export default async function Page(props: { searchParams: Promise<any> }) {
}); });
} }
const userResponse = await getUserByID(userId); const userResponse = await getUserByID({ serviceUrl, userId });
if (userResponse) { if (userResponse) {
user = userResponse.user; user = userResponse.user;
if (user?.type.case === "human") { if (user?.type.case === "human") {

View File

@@ -34,8 +34,12 @@ export async function createServiceForHost<T extends ServiceClass>(
token = process.env.ZITADEL_SERVICE_USER_TOKEN; token = process.env.ZITADEL_SERVICE_USER_TOKEN;
} }
if (!serviceUrl || !token) { if (!serviceUrl) {
throw new Error("No instance url or token found"); throw new Error("No instance url found");
}
if (!token) {
throw new Error("No token found");
} }
const transport = createServerTransport(token, { const transport = createServerTransport(token, {
@@ -48,9 +52,10 @@ export async function createServiceForHost<T extends ServiceClass>(
export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): string { export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): string {
let instanceUrl: string = process.env.ZITADEL_API_URL; 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 // use the forwarded host if available (multitenant), otherwise fall back to the host of the deployment itself
if (headers.get("x-zitadel-forward-host")) { if (forwardedHost) {
instanceUrl = headers.get("x-zitadel-forward-host") as string; instanceUrl = forwardedHost;
instanceUrl = instanceUrl.startsWith("https://") instanceUrl = instanceUrl.startsWith("https://")
? instanceUrl ? instanceUrl
: `https://${instanceUrl}`; : `https://${instanceUrl}`;