mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-13 13:01:38 +00:00
fix zlib export
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { SessionsList } from "@/components/sessions-list";
|
import { SessionsList } from "@/components/sessions-list";
|
||||||
import { getAllSessionCookieIds } from "@/lib/cookies";
|
import { getAllSessionCookieIds } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
getDefaultOrg,
|
getDefaultOrg,
|
||||||
|
@@ -5,7 +5,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getActiveIdentityProviders,
|
getActiveIdentityProviders,
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
|||||||
import { ChooseAuthenticatorToLogin } from "@/components/choose-authenticator-to-login";
|
import { ChooseAuthenticatorToLogin } from "@/components/choose-authenticator-to-login";
|
||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
getLoginSettings,
|
getLoginSettings,
|
||||||
|
@@ -4,7 +4,7 @@ import { linkingFailed } from "@/components/idps/pages/linking-failed";
|
|||||||
import { linkingSuccess } from "@/components/idps/pages/linking-success";
|
import { linkingSuccess } from "@/components/idps/pages/linking-success";
|
||||||
import { loginFailed } from "@/components/idps/pages/login-failed";
|
import { loginFailed } from "@/components/idps/pages/login-failed";
|
||||||
import { loginSuccess } from "@/components/idps/pages/login-success";
|
import { loginSuccess } from "@/components/idps/pages/login-success";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
addHuman,
|
addHuman,
|
||||||
addIDPLink,
|
addIDPLink,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { getActiveIdentityProviders, getBrandingSettings } from "@/lib/zitadel";
|
import { getActiveIdentityProviders, getBrandingSettings } from "@/lib/zitadel";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { Alert, AlertType } from "@/components/alert";
|
import { Alert, AlertType } from "@/components/alert";
|
||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { InviteForm } from "@/components/invite-form";
|
import { InviteForm } from "@/components/invite-form";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
getDefaultOrg,
|
getDefaultOrg,
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
|||||||
import { Button, ButtonVariants } from "@/components/button";
|
import { Button, ButtonVariants } from "@/components/button";
|
||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { getBrandingSettings, getDefaultOrg, getUserByID } from "@/lib/zitadel";
|
import { getBrandingSettings, getDefaultOrg, getUserByID } from "@/lib/zitadel";
|
||||||
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
|
import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
import { SignInWithIdp } from "@/components/sign-in-with-idp";
|
||||||
import { UsernameForm } from "@/components/username-form";
|
import { UsernameForm } from "@/components/username-form";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getActiveIdentityProviders,
|
getActiveIdentityProviders,
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -4,7 +4,7 @@ import { ChooseSecondFactor } from "@/components/choose-second-factor";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -4,7 +4,7 @@ import { ChooseSecondFactorToSetup } from "@/components/choose-second-factor-to-
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { LoginOTP } from "@/components/login-otp";
|
import { LoginOTP } from "@/components/login-otp";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -4,7 +4,7 @@ import { Button, ButtonVariants } from "@/components/button";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { TotpRegister } from "@/components/totp-register";
|
import { TotpRegister } from "@/components/totp-register";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
addOTPEmail,
|
addOTPEmail,
|
||||||
|
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { LoginPasskey } from "@/components/login-passkey";
|
import { LoginPasskey } from "@/components/login-passkey";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { RegisterPasskey } from "@/components/register-passkey";
|
import { RegisterPasskey } from "@/components/register-passkey";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import { getBrandingSettings } from "@/lib/zitadel";
|
import { getBrandingSettings } from "@/lib/zitadel";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert } from "@/components/alert";
|
|||||||
import { ChangePasswordForm } from "@/components/change-password-form";
|
import { ChangePasswordForm } from "@/components/change-password-form";
|
||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert } from "@/components/alert";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { PasswordForm } from "@/components/password-form";
|
import { PasswordForm } from "@/components/password-form";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert, AlertType } from "@/components/alert";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { SetPasswordForm } from "@/components/set-password-form";
|
import { SetPasswordForm } from "@/components/set-password-form";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { RegisterForm } from "@/components/register-form";
|
import { RegisterForm } from "@/components/register-form";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
getDefaultOrg,
|
getDefaultOrg,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { SetRegisterPasswordForm } from "@/components/set-register-password-form";
|
import { SetRegisterPasswordForm } from "@/components/set-register-password-form";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
getDefaultOrg,
|
getDefaultOrg,
|
||||||
|
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { SelfServiceMenu } from "@/components/self-service-menu";
|
import { SelfServiceMenu } from "@/components/self-service-menu";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getMostRecentCookieWithLoginname } from "@/lib/cookies";
|
import { getMostRecentCookieWithLoginname } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import {
|
import {
|
||||||
createCallback,
|
createCallback,
|
||||||
createResponse,
|
createResponse,
|
||||||
|
@@ -3,7 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme";
|
|||||||
import { LoginPasskey } from "@/components/login-passkey";
|
import { LoginPasskey } from "@/components/login-passkey";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getSessionCookieById } from "@/lib/cookies";
|
import { getSessionCookieById } from "@/lib/cookies";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
@@ -2,7 +2,7 @@ import { Alert } from "@/components/alert";
|
|||||||
import { DynamicTheme } from "@/components/dynamic-theme";
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
||||||
import { RegisterU2f } from "@/components/register-u2f";
|
import { RegisterU2f } from "@/components/register-u2f";
|
||||||
import { UserAvatar } from "@/components/user-avatar";
|
import { UserAvatar } from "@/components/user-avatar";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import { getBrandingSettings } from "@/lib/zitadel";
|
import { getBrandingSettings } from "@/lib/zitadel";
|
||||||
import { getLocale, getTranslations } from "next-intl/server";
|
import { getLocale, getTranslations } from "next-intl/server";
|
||||||
|
@@ -4,7 +4,7 @@ import { UserAvatar } from "@/components/user-avatar";
|
|||||||
import { VerifyForm } from "@/components/verify-form";
|
import { VerifyForm } from "@/components/verify-form";
|
||||||
import { VerifyRedirectButton } from "@/components/verify-redirect-button";
|
import { VerifyRedirectButton } from "@/components/verify-redirect-button";
|
||||||
import { sendEmailCode } from "@/lib/server/verify";
|
import { sendEmailCode } from "@/lib/server/verify";
|
||||||
import { getServiceUrlFromHeaders } from "@/lib/service";
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { loadMostRecentSession } from "@/lib/session";
|
import { loadMostRecentSession } from "@/lib/session";
|
||||||
import {
|
import {
|
||||||
getBrandingSettings,
|
getBrandingSettings,
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import { createServiceForHost, getServiceUrlFromHeaders } from "@/lib/service";
|
import { createServiceForHost } from "@/lib/service";
|
||||||
|
import { getServiceUrlFromHeaders } from "@/lib/service-url";
|
||||||
import { Client } from "@zitadel/client";
|
import { Client } from "@zitadel/client";
|
||||||
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb";
|
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb";
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
|
58
apps/login/src/lib/service-url.ts
Normal file
58
apps/login/src/lib/service-url.ts
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
import { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
|
||||||
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the service url and region from the headers if used in a multitenant context (host, x-zitadel-forward-host header)
|
||||||
|
* or falls back to the ZITADEL_API_URL for a self hosting deployment
|
||||||
|
* or falls back to the host header for a self hosting deployment using custom domains
|
||||||
|
* @param headers
|
||||||
|
* @returns the service url and region from the headers
|
||||||
|
* @throws if the service url could not be determined
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): {
|
||||||
|
serviceUrl: string;
|
||||||
|
} {
|
||||||
|
let instanceUrl;
|
||||||
|
|
||||||
|
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 (forwardedHost) {
|
||||||
|
instanceUrl = forwardedHost;
|
||||||
|
instanceUrl = instanceUrl.startsWith("http://")
|
||||||
|
? instanceUrl
|
||||||
|
: `https://${instanceUrl}`;
|
||||||
|
} else if (process.env.ZITADEL_API_URL) {
|
||||||
|
instanceUrl = process.env.ZITADEL_API_URL;
|
||||||
|
} else {
|
||||||
|
const host = headers.get("host");
|
||||||
|
|
||||||
|
if (host) {
|
||||||
|
const [hostname, port] = host.split(":");
|
||||||
|
if (hostname !== "localhost") {
|
||||||
|
instanceUrl = host.startsWith("http") ? host : `https://${host}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!instanceUrl) {
|
||||||
|
throw new Error("Service URL could not be determined");
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
serviceUrl: instanceUrl,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function constructUrl(request: NextRequest, path: string) {
|
||||||
|
const forwardedProto = request.headers.get("x-forwarded-proto")
|
||||||
|
? `${request.headers.get("x-forwarded-proto")}:`
|
||||||
|
: request.nextUrl.protocol;
|
||||||
|
|
||||||
|
const forwardedHost =
|
||||||
|
request.headers.get("x-zitadel-forward-host") ??
|
||||||
|
request.headers.get("x-forwarded-host") ??
|
||||||
|
request.headers.get("host");
|
||||||
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
||||||
|
return new URL(`${basePath}${path}`, `${forwardedProto}//${forwardedHost}`);
|
||||||
|
}
|
@@ -7,7 +7,6 @@ import { SAMLService } from "@zitadel/proto/zitadel/saml/v2/saml_service_pb";
|
|||||||
import { SessionService } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
import { SessionService } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
||||||
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb";
|
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb";
|
||||||
import { UserService } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
import { UserService } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||||
import { ReadonlyHeaders } from "next/dist/server/web/spec-extension/adapters/headers";
|
|
||||||
import { NextRequest } from "next/server";
|
import { NextRequest } from "next/server";
|
||||||
import { systemAPIToken } from "./api";
|
import { systemAPIToken } from "./api";
|
||||||
|
|
||||||
@@ -67,49 +66,6 @@ export async function createServiceForHost<T extends ServiceClass>(
|
|||||||
return createClientFor<T>(service)(transport);
|
return createClientFor<T>(service)(transport);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts the service url and region from the headers if used in a multitenant context (host, x-zitadel-forward-host header)
|
|
||||||
* or falls back to the ZITADEL_API_URL for a self hosting deployment
|
|
||||||
* or falls back to the host header for a self hosting deployment using custom domains
|
|
||||||
* @param headers
|
|
||||||
* @returns the service url and region from the headers
|
|
||||||
* @throws if the service url could not be determined
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export function getServiceUrlFromHeaders(headers: ReadonlyHeaders): {
|
|
||||||
serviceUrl: string;
|
|
||||||
} {
|
|
||||||
let instanceUrl;
|
|
||||||
|
|
||||||
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 (forwardedHost) {
|
|
||||||
instanceUrl = forwardedHost;
|
|
||||||
instanceUrl = instanceUrl.startsWith("http://")
|
|
||||||
? instanceUrl
|
|
||||||
: `https://${instanceUrl}`;
|
|
||||||
} else if (process.env.ZITADEL_API_URL) {
|
|
||||||
instanceUrl = process.env.ZITADEL_API_URL;
|
|
||||||
} else {
|
|
||||||
const host = headers.get("host");
|
|
||||||
|
|
||||||
if (host) {
|
|
||||||
const [hostname, port] = host.split(":");
|
|
||||||
if (hostname !== "localhost") {
|
|
||||||
instanceUrl = host.startsWith("http") ? host : `https://${host}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!instanceUrl) {
|
|
||||||
throw new Error("Service URL could not be determined");
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
serviceUrl: instanceUrl,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function constructUrl(request: NextRequest, path: string) {
|
export function constructUrl(request: NextRequest, path: string) {
|
||||||
const forwardedProto = request.headers.get("x-forwarded-proto")
|
const forwardedProto = request.headers.get("x-forwarded-proto")
|
||||||
? `${request.headers.get("x-forwarded-proto")}:`
|
? `${request.headers.get("x-forwarded-proto")}:`
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
import { DEFAULT_CSP } from "../constants/csp";
|
import { DEFAULT_CSP } from "../constants/csp";
|
||||||
import { getServiceUrlFromHeaders } from "./lib/service";
|
import { getServiceUrlFromHeaders } from "./lib/service-url";
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
|
Reference in New Issue
Block a user