From d378c6504ecfeb3b7c0db8baa1ef9ca531a55f60 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Tue, 28 Jan 2025 09:47:35 +0100 Subject: [PATCH] host change everywhere --- apps/login/src/app/(login)/accounts/page.tsx | 5 ++++- .../src/app/(login)/authenticator/set/page.tsx | 5 ++++- .../(login)/idp/[provider]/failure/page.tsx | 5 ++++- .../(login)/idp/[provider]/success/page.tsx | 5 ++++- apps/login/src/app/(login)/idp/page.tsx | 5 ++++- apps/login/src/app/(login)/invite/page.tsx | 5 ++++- .../src/app/(login)/invite/success/page.tsx | 5 ++++- apps/login/src/app/(login)/loginname/page.tsx | 5 ++++- apps/login/src/app/(login)/mfa/page.tsx | 5 ++++- apps/login/src/app/(login)/mfa/set/page.tsx | 5 ++++- .../src/app/(login)/otp/[method]/page.tsx | 5 ++++- .../src/app/(login)/otp/[method]/set/page.tsx | 5 ++++- apps/login/src/app/(login)/passkey/page.tsx | 5 ++++- .../login/src/app/(login)/passkey/set/page.tsx | 5 ++++- .../src/app/(login)/password/change/page.tsx | 5 ++++- apps/login/src/app/(login)/password/page.tsx | 5 ++++- .../src/app/(login)/password/set/page.tsx | 5 ++++- apps/login/src/app/(login)/register/page.tsx | 5 ++++- .../src/app/(login)/register/password/page.tsx | 5 ++++- apps/login/src/app/(login)/signedin/page.tsx | 5 ++++- apps/login/src/app/(login)/u2f/page.tsx | 5 ++++- apps/login/src/app/(login)/u2f/set/page.tsx | 5 ++++- apps/login/src/app/(login)/verify/page.tsx | 5 ++++- apps/login/src/app/login/route.ts | 5 ++++- apps/login/src/lib/server/cookie.ts | 13 ++++++++++--- apps/login/src/lib/server/idp.ts | 9 +++++++-- apps/login/src/lib/server/invite.ts | 5 ++++- apps/login/src/lib/server/loginname.ts | 13 ++++++++++--- apps/login/src/lib/server/otp.ts | 5 ++++- apps/login/src/lib/server/passkeys.ts | 13 ++++++++++--- apps/login/src/lib/server/password.ts | 12 +++++++++--- apps/login/src/lib/server/register.ts | 5 ++++- apps/login/src/lib/server/session.ts | 17 +++++++++++++---- apps/login/src/lib/server/u2f.ts | 9 +++++++-- apps/login/src/lib/server/verify.ts | 18 +++++++++++++----- 35 files changed, 187 insertions(+), 52 deletions(-) diff --git a/apps/login/src/app/(login)/accounts/page.tsx b/apps/login/src/app/(login)/accounts/page.tsx index 99e7acb408..f17c799a93 100644 --- a/apps/login/src/app/(login)/accounts/page.tsx +++ b/apps/login/src/app/(login)/accounts/page.tsx @@ -1,6 +1,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SessionsList } from "@/components/sessions-list"; import { getAllSessionCookieIds } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings, getDefaultOrg, @@ -37,7 +38,9 @@ export default async function Page(props: { const authRequestId = searchParams?.authRequestId; const organization = searchParams?.organization; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/authenticator/set/page.tsx b/apps/login/src/app/(login)/authenticator/set/page.tsx index 55a4d3c74e..1c88014416 100644 --- a/apps/login/src/app/(login)/authenticator/set/page.tsx +++ b/apps/login/src/app/(login)/authenticator/set/page.tsx @@ -5,6 +5,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SignInWithIdp } from "@/components/sign-in-with-idp"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getActiveIdentityProviders, @@ -28,7 +29,9 @@ export default async function Page(props: { const { loginName, authRequestId, organization, sessionId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx b/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx index 13bbb44e31..e368b8c070 100644 --- a/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx +++ b/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx @@ -1,4 +1,5 @@ import { DynamicTheme } from "@/components/dynamic-theme"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings } from "@/lib/zitadel"; import { IdentityProviderType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb"; import { getLocale, getTranslations } from "next-intl/server"; @@ -23,7 +24,9 @@ export default async function Page(props: { const { organization } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/idp/[provider]/success/page.tsx b/apps/login/src/app/(login)/idp/[provider]/success/page.tsx index 0fdc44f6d5..bfd78ea3fc 100644 --- a/apps/login/src/app/(login)/idp/[provider]/success/page.tsx +++ b/apps/login/src/app/(login)/idp/[provider]/success/page.tsx @@ -5,6 +5,7 @@ import { linkingSuccess } from "@/components/idps/pages/linking-success"; import { loginFailed } from "@/components/idps/pages/login-failed"; import { loginSuccess } from "@/components/idps/pages/login-success"; import { idpTypeToIdentityProviderType, PROVIDER_MAPPING } from "@/lib/idp"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { addHuman, addIDPLink, @@ -38,7 +39,9 @@ export default async function Page(props: { const { id, token, authRequestId, organization, link } = searchParams; const { provider } = params; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/idp/page.tsx b/apps/login/src/app/(login)/idp/page.tsx index 8b91d7c064..56897c28f3 100644 --- a/apps/login/src/app/(login)/idp/page.tsx +++ b/apps/login/src/app/(login)/idp/page.tsx @@ -1,5 +1,6 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SignInWithIdp } from "@/components/sign-in-with-idp"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getActiveIdentityProviders, getBrandingSettings } from "@/lib/zitadel"; import { getLocale, getTranslations } from "next-intl/server"; import { headers } from "next/headers"; @@ -14,7 +15,9 @@ export default async function Page(props: { const authRequestId = searchParams?.authRequestId; const organization = searchParams?.organization; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/invite/page.tsx b/apps/login/src/app/(login)/invite/page.tsx index 5d99d3e4a4..9b92be5381 100644 --- a/apps/login/src/app/(login)/invite/page.tsx +++ b/apps/login/src/app/(login)/invite/page.tsx @@ -1,6 +1,7 @@ import { Alert, AlertType } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { InviteForm } from "@/components/invite-form"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings, getDefaultOrg, @@ -19,7 +20,9 @@ export default async function Page(props: { let { firstname, lastname, email, organization } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/invite/success/page.tsx b/apps/login/src/app/(login)/invite/success/page.tsx index 8bb7a68094..5ae7300ea0 100644 --- a/apps/login/src/app/(login)/invite/success/page.tsx +++ b/apps/login/src/app/(login)/invite/success/page.tsx @@ -2,6 +2,7 @@ import { Alert, AlertType } from "@/components/alert"; import { Button, ButtonVariants } from "@/components/button"; import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings, getDefaultOrg, getUserByID } from "@/lib/zitadel"; import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb"; import { getLocale, getTranslations } from "next-intl/server"; @@ -17,7 +18,9 @@ export default async function Page(props: { let { userId, organization } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/loginname/page.tsx b/apps/login/src/app/(login)/loginname/page.tsx index 1c513d74a1..21881d2253 100644 --- a/apps/login/src/app/(login)/loginname/page.tsx +++ b/apps/login/src/app/(login)/loginname/page.tsx @@ -1,6 +1,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SignInWithIdp } from "@/components/sign-in-with-idp"; import { UsernameForm } from "@/components/username-form"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getActiveIdentityProviders, getBrandingSettings, @@ -24,7 +25,9 @@ export default async function Page(props: { const suffix = searchParams?.suffix; const submit: boolean = searchParams?.submit === "true"; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/mfa/page.tsx b/apps/login/src/app/(login)/mfa/page.tsx index 62625c7efa..f2df51847d 100644 --- a/apps/login/src/app/(login)/mfa/page.tsx +++ b/apps/login/src/app/(login)/mfa/page.tsx @@ -4,6 +4,7 @@ import { ChooseSecondFactor } from "@/components/choose-second-factor"; import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -23,7 +24,9 @@ export default async function Page(props: { const { loginName, authRequestId, organization, sessionId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/mfa/set/page.tsx b/apps/login/src/app/(login)/mfa/set/page.tsx index d92e1ce820..4adfa87fdb 100644 --- a/apps/login/src/app/(login)/mfa/set/page.tsx +++ b/apps/login/src/app/(login)/mfa/set/page.tsx @@ -4,6 +4,7 @@ import { ChooseSecondFactorToSetup } from "@/components/choose-second-factor-to- import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -50,7 +51,9 @@ export default async function Page(props: { sessionId, } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/otp/[method]/page.tsx b/apps/login/src/app/(login)/otp/[method]/page.tsx index 1f57d6c3be..3e9b41f902 100644 --- a/apps/login/src/app/(login)/otp/[method]/page.tsx +++ b/apps/login/src/app/(login)/otp/[method]/page.tsx @@ -3,6 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { LoginOTP } from "@/components/login-otp"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -22,7 +23,9 @@ export default async function Page(props: { const t = await getTranslations({ locale, namespace: "otp" }); const tError = await getTranslations({ locale, namespace: "error" }); - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/otp/[method]/set/page.tsx b/apps/login/src/app/(login)/otp/[method]/set/page.tsx index b341cc47ba..e9c3da8848 100644 --- a/apps/login/src/app/(login)/otp/[method]/set/page.tsx +++ b/apps/login/src/app/(login)/otp/[method]/set/page.tsx @@ -4,6 +4,7 @@ import { Button, ButtonVariants } from "@/components/button"; import { DynamicTheme } from "@/components/dynamic-theme"; import { TotpRegister } from "@/components/totp-register"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { addOTPEmail, @@ -32,7 +33,9 @@ export default async function Page(props: { searchParams; const { method } = params; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/passkey/page.tsx b/apps/login/src/app/(login)/passkey/page.tsx index f2d67fe9bf..fad64ebac0 100644 --- a/apps/login/src/app/(login)/passkey/page.tsx +++ b/apps/login/src/app/(login)/passkey/page.tsx @@ -3,6 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { LoginPasskey } from "@/components/login-passkey"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -23,7 +24,9 @@ export default async function Page(props: { const { loginName, altPassword, authRequestId, organization, sessionId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/passkey/set/page.tsx b/apps/login/src/app/(login)/passkey/set/page.tsx index 5a768eef47..184eed8296 100644 --- a/apps/login/src/app/(login)/passkey/set/page.tsx +++ b/apps/login/src/app/(login)/passkey/set/page.tsx @@ -2,6 +2,7 @@ import { Alert, AlertType } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { RegisterPasskey } from "@/components/register-passkey"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings } from "@/lib/zitadel"; import { getLocale, getTranslations } from "next-intl/server"; @@ -18,7 +19,9 @@ export default async function Page(props: { const { loginName, prompt, organization, authRequestId, userId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/password/change/page.tsx b/apps/login/src/app/(login)/password/change/page.tsx index f242d364d4..304ad4ec7b 100644 --- a/apps/login/src/app/(login)/password/change/page.tsx +++ b/apps/login/src/app/(login)/password/change/page.tsx @@ -2,6 +2,7 @@ import { Alert } from "@/components/alert"; import { ChangePasswordForm } from "@/components/change-password-form"; import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -14,7 +15,9 @@ import { headers } from "next/headers"; export default async function Page(props: { searchParams: Promise>; }) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/password/page.tsx b/apps/login/src/app/(login)/password/page.tsx index 9ef9ec430d..6adfb82754 100644 --- a/apps/login/src/app/(login)/password/page.tsx +++ b/apps/login/src/app/(login)/password/page.tsx @@ -2,6 +2,7 @@ import { Alert } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { PasswordForm } from "@/components/password-form"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -23,7 +24,9 @@ export default async function Page(props: { let { loginName, organization, authRequestId, alt } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/password/set/page.tsx b/apps/login/src/app/(login)/password/set/page.tsx index 61ced3b1e6..f951e40a6a 100644 --- a/apps/login/src/app/(login)/password/set/page.tsx +++ b/apps/login/src/app/(login)/password/set/page.tsx @@ -2,6 +2,7 @@ import { Alert, AlertType } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { SetPasswordForm } from "@/components/set-password-form"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -25,7 +26,9 @@ export default async function Page(props: { const { userId, loginName, organization, authRequestId, code, initial } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/register/page.tsx b/apps/login/src/app/(login)/register/page.tsx index 08943c3048..0a1deb6a23 100644 --- a/apps/login/src/app/(login)/register/page.tsx +++ b/apps/login/src/app/(login)/register/page.tsx @@ -1,5 +1,6 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { RegisterForm } from "@/components/register-form"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings, getDefaultOrg, @@ -21,7 +22,9 @@ export default async function Page(props: { let { firstname, lastname, email, organization, authRequestId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/register/password/page.tsx b/apps/login/src/app/(login)/register/password/page.tsx index 6fed1af8b2..549b7a90ef 100644 --- a/apps/login/src/app/(login)/register/password/page.tsx +++ b/apps/login/src/app/(login)/register/password/page.tsx @@ -1,5 +1,6 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SetRegisterPasswordForm } from "@/components/set-register-password-form"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { getBrandingSettings, getDefaultOrg, @@ -21,7 +22,9 @@ export default async function Page(props: { let { firstname, lastname, email, organization, authRequestId } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/signedin/page.tsx b/apps/login/src/app/(login)/signedin/page.tsx index d8a4ebaece..2658a915ca 100644 --- a/apps/login/src/app/(login)/signedin/page.tsx +++ b/apps/login/src/app/(login)/signedin/page.tsx @@ -3,6 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { SelfServiceMenu } from "@/components/self-service-menu"; import { UserAvatar } from "@/components/user-avatar"; import { getMostRecentCookieWithLoginname } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { createCallback, getBrandingSettings, @@ -59,7 +60,9 @@ export default async function Page(props: { searchParams: Promise }) { const locale = getLocale(); const t = await getTranslations({ locale, namespace: "signedin" }); - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/u2f/page.tsx b/apps/login/src/app/(login)/u2f/page.tsx index a9e468b572..f588c7d62c 100644 --- a/apps/login/src/app/(login)/u2f/page.tsx +++ b/apps/login/src/app/(login)/u2f/page.tsx @@ -3,6 +3,7 @@ import { DynamicTheme } from "@/components/dynamic-theme"; import { LoginPasskey } from "@/components/login-passkey"; import { UserAvatar } from "@/components/user-avatar"; import { getSessionCookieById } from "@/lib/cookies"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, getSession } from "@/lib/zitadel"; import { getLocale, getTranslations } from "next-intl/server"; @@ -18,7 +19,9 @@ export default async function Page(props: { const { loginName, authRequestId, sessionId, organization } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/u2f/set/page.tsx b/apps/login/src/app/(login)/u2f/set/page.tsx index 47564abd9d..1ebe4d5edd 100644 --- a/apps/login/src/app/(login)/u2f/set/page.tsx +++ b/apps/login/src/app/(login)/u2f/set/page.tsx @@ -2,6 +2,7 @@ import { Alert } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { RegisterU2f } from "@/components/register-u2f"; import { UserAvatar } from "@/components/user-avatar"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings } from "@/lib/zitadel"; import { getLocale, getTranslations } from "next-intl/server"; @@ -17,7 +18,9 @@ export default async function Page(props: { const { loginName, organization, authRequestId, checkAfter } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/(login)/verify/page.tsx b/apps/login/src/app/(login)/verify/page.tsx index 0eca62e561..1000fcadeb 100644 --- a/apps/login/src/app/(login)/verify/page.tsx +++ b/apps/login/src/app/(login)/verify/page.tsx @@ -4,6 +4,7 @@ import { UserAvatar } from "@/components/user-avatar"; import { VerifyForm } from "@/components/verify-form"; import { VerifyRedirectButton } from "@/components/verify-redirect-button"; import { sendEmailCode } from "@/lib/server/verify"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, @@ -24,7 +25,9 @@ export default async function Page(props: { searchParams: Promise }) { const { userId, loginName, code, organization, authRequestId, invite } = searchParams; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/app/login/route.ts b/apps/login/src/app/login/route.ts index de38d4bcb6..42599f00b3 100644 --- a/apps/login/src/app/login/route.ts +++ b/apps/login/src/app/login/route.ts @@ -1,6 +1,7 @@ import { getAllSessions } from "@/lib/cookies"; import { idpTypeToSlug } from "@/lib/idp"; import { sendLoginname, SendLoginnameCommand } from "@/lib/server/loginname"; +import { getApiUrlOfHeaders } from "@/lib/service"; import { createCallback, getActiveIdentityProviders, @@ -191,7 +192,9 @@ export async function GET(request: NextRequest) { const authRequestId = searchParams.get("authRequest"); const sessionId = searchParams.get("sessionId"); - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/lib/server/cookie.ts b/apps/login/src/lib/server/cookie.ts index 3e3347e750..e9cdd80493 100644 --- a/apps/login/src/lib/server/cookie.ts +++ b/apps/login/src/lib/server/cookie.ts @@ -15,6 +15,7 @@ import { import { Session } from "@zitadel/proto/zitadel/session/v2/session_pb"; import { Checks } from "@zitadel/proto/zitadel/session/v2/session_service_pb"; import { headers } from "next/headers"; +import { getApiUrlOfHeaders } from "../service"; type CustomCookieData = { id: string; @@ -33,7 +34,9 @@ export async function createSessionAndUpdateCookie( authRequestId: string | undefined, lifetime?: Duration, ): Promise { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); @@ -98,7 +101,9 @@ export async function createSessionForIdpAndUpdateCookie( authRequestId: string | undefined, lifetime?: Duration, ): Promise { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); @@ -163,7 +168,9 @@ export async function setSessionAndUpdateCookie( authRequestId?: string, lifetime?: Duration, ) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); diff --git a/apps/login/src/lib/server/idp.ts b/apps/login/src/lib/server/idp.ts index b43cd4705d..560611b407 100644 --- a/apps/login/src/lib/server/idp.ts +++ b/apps/login/src/lib/server/idp.ts @@ -7,6 +7,7 @@ import { } from "@/lib/zitadel"; import { headers } from "next/headers"; import { getNextUrl } from "../client"; +import { getApiUrlOfHeaders } from "../service"; import { checkEmailVerification } from "../verify-helper"; import { createSessionForIdpAndUpdateCookie } from "./cookie"; @@ -17,7 +18,9 @@ export type StartIDPFlowCommand = { }; export async function startIDPFlow(command: StartIDPFlowCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get host" }; @@ -56,7 +59,9 @@ type CreateNewSessionCommand = { export async function createNewSessionFromIdpIntent( command: CreateNewSessionCommand, ) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get domain" }; diff --git a/apps/login/src/lib/server/invite.ts b/apps/login/src/lib/server/invite.ts index 4bfb55d10b..332155ae3a 100644 --- a/apps/login/src/lib/server/invite.ts +++ b/apps/login/src/lib/server/invite.ts @@ -3,6 +3,7 @@ import { addHumanUser, createInviteCode } from "@/lib/zitadel"; import { Factors } from "@zitadel/proto/zitadel/session/v2/session_pb"; import { headers } from "next/headers"; +import { getApiUrlOfHeaders } from "../service"; type InviteUserCommand = { email: string; @@ -20,7 +21,9 @@ export type RegisterUserResponse = { }; export async function inviteUser(command: InviteUserCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get domain" }; diff --git a/apps/login/src/lib/server/loginname.ts b/apps/login/src/lib/server/loginname.ts index 98c742ca42..bf9664c29d 100644 --- a/apps/login/src/lib/server/loginname.ts +++ b/apps/login/src/lib/server/loginname.ts @@ -8,6 +8,7 @@ import { idpTypeToIdentityProviderType, idpTypeToSlug } from "../idp"; import { PasskeysType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb"; import { UserState } from "@zitadel/proto/zitadel/user/v2/user_pb"; +import { getApiUrlOfHeaders } from "../service"; import { checkInvite } from "../verify-helper"; import { getActiveIdentityProviders, @@ -32,7 +33,9 @@ export type SendLoginnameCommand = { const ORG_SUFFIX_REGEX = /(?<=@)(.+)/; export async function sendLoginname(command: SendLoginnameCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); @@ -76,7 +79,9 @@ export async function sendLoginname(command: SendLoginnameCommand) { }); if (identityProviders.length === 1) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get host" }; @@ -123,7 +128,9 @@ export async function sendLoginname(command: SendLoginnameCommand) { ); if (identityProviders.length === 1) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get host" }; diff --git a/apps/login/src/lib/server/otp.ts b/apps/login/src/lib/server/otp.ts index 53e1ca3b16..d70fffaa2c 100644 --- a/apps/login/src/lib/server/otp.ts +++ b/apps/login/src/lib/server/otp.ts @@ -13,6 +13,7 @@ import { getSessionCookieById, getSessionCookieByLoginName, } from "../cookies"; +import { getApiUrlOfHeaders } from "../service"; import { getLoginSettings } from "../zitadel"; export type SetOTPCommand = { @@ -25,7 +26,9 @@ export type SetOTPCommand = { }; export async function setOTP(command: SetOTPCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); diff --git a/apps/login/src/lib/server/passkeys.ts b/apps/login/src/lib/server/passkeys.ts index 7a662fbd88..2ffa594ff5 100644 --- a/apps/login/src/lib/server/passkeys.ts +++ b/apps/login/src/lib/server/passkeys.ts @@ -22,6 +22,7 @@ import { getSessionCookieById, getSessionCookieByLoginName, } from "../cookies"; +import { getApiUrlOfHeaders } from "../service"; import { checkEmailVerification } from "../verify-helper"; import { setSessionAndUpdateCookie } from "./cookie"; @@ -41,7 +42,9 @@ export async function registerPasskeyLink( ): Promise { const { sessionId } = command; - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); @@ -86,7 +89,9 @@ export async function registerPasskeyLink( } export async function verifyPasskeyRegistration(command: VerifyPasskeyCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { throw new Error("Could not get domain"); @@ -152,7 +157,9 @@ export async function sendPasskey(command: SendPasskeyCommand) { }; } - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get host" }; diff --git a/apps/login/src/lib/server/password.ts b/apps/login/src/lib/server/password.ts index 7a417e803a..6de1ca2bb4 100644 --- a/apps/login/src/lib/server/password.ts +++ b/apps/login/src/lib/server/password.ts @@ -44,7 +44,9 @@ type ResetPasswordCommand = { }; export async function resetPassword(command: ResetPasswordCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -76,7 +78,9 @@ export type UpdateSessionCommand = { }; export async function sendPassword(command: UpdateSessionCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -249,7 +253,9 @@ export async function changePassword(command: { userId: string; password: string; }) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/lib/server/register.ts b/apps/login/src/lib/server/register.ts index 38dc025b8a..1aa2f2efdd 100644 --- a/apps/login/src/lib/server/register.ts +++ b/apps/login/src/lib/server/register.ts @@ -10,6 +10,7 @@ import { } from "@zitadel/proto/zitadel/session/v2/session_service_pb"; import { headers } from "next/headers"; import { getNextUrl } from "../client"; +import { getApiUrlOfHeaders } from "../service"; import { checkEmailVerification } from "../verify-helper"; type RegisterUserCommand = { @@ -27,7 +28,9 @@ export type RegisterUserResponse = { factors: Factors | undefined; }; export async function registerUser(command: RegisterUserCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/lib/server/session.ts b/apps/login/src/lib/server/session.ts index 84f028db44..9b95e77a6c 100644 --- a/apps/login/src/lib/server/session.ts +++ b/apps/login/src/lib/server/session.ts @@ -18,12 +18,15 @@ import { getSessionCookieByLoginName, removeSessionFromCookie, } from "../cookies"; +import { getApiUrlOfHeaders } from "../service"; export async function continueWithSession({ authRequestId, ...session }: Session & { authRequestId?: string }) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -89,7 +92,9 @@ export async function updateSession(options: UpdateSessionCommand) { }; } - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "Could not get host" }; @@ -151,7 +156,9 @@ type ClearSessionOptions = { }; export async function clearSession(options: ClearSessionOptions) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -177,7 +184,9 @@ type CleanupSessionCommand = { }; export async function cleanupSession({ sessionId }: CleanupSessionCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/lib/server/u2f.ts b/apps/login/src/lib/server/u2f.ts index 8620350656..b544b8d75b 100644 --- a/apps/login/src/lib/server/u2f.ts +++ b/apps/login/src/lib/server/u2f.ts @@ -6,6 +6,7 @@ import { VerifyU2FRegistrationRequestSchema } from "@zitadel/proto/zitadel/user/ import { headers } from "next/headers"; import { userAgent } from "next/server"; import { getSessionCookieById } from "../cookies"; +import { getApiUrlOfHeaders } from "../service"; type RegisterU2FCommand = { sessionId: string; @@ -19,7 +20,9 @@ type VerifyU2FCommand = { }; export async function addU2F(command: RegisterU2FCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -55,7 +58,9 @@ export async function addU2F(command: RegisterU2FCommand) { } export async function verifyU2F(command: VerifyU2FCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); diff --git a/apps/login/src/lib/server/verify.ts b/apps/login/src/lib/server/verify.ts index 0b70b41d1f..21a8e03fcd 100644 --- a/apps/login/src/lib/server/verify.ts +++ b/apps/login/src/lib/server/verify.ts @@ -19,6 +19,7 @@ import { User } from "@zitadel/proto/zitadel/user/v2/user_pb"; import { headers } from "next/headers"; import { getNextUrl } from "../client"; import { getSessionCookieByLoginName } from "../cookies"; +import { getApiUrlOfHeaders } from "../service"; import { loadMostRecentSession } from "../session"; import { checkMFAFactors } from "../verify-helper"; import { createSessionAndUpdateCookie } from "./cookie"; @@ -28,7 +29,9 @@ export async function verifyTOTP( loginName?: string, organization?: string, ) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -63,7 +66,9 @@ type VerifyUserByEmailCommand = { }; export async function sendVerification(command: VerifyUserByEmailCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); @@ -245,7 +250,9 @@ type resendVerifyEmailCommand = { }; export async function resendVerification(command: resendVerifyEmailCommand) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host) { return { error: "No host found" }; @@ -267,7 +274,6 @@ type sendEmailCommand = { }; export async function sendEmailCode(command: sendEmailCommand) { - const host = (await headers()).get("host"); return zitadelSendEmailCode({ userId: command.userId, host: command.host, @@ -286,7 +292,9 @@ export type SendVerificationRedirectWithoutCheckCommand = { export async function sendVerificationRedirectWithoutCheck( command: SendVerificationRedirectWithoutCheckCommand, ) { - const host = (await headers()).get("host"); + const _headers = await headers(); + const instanceUrl = getApiUrlOfHeaders(_headers); + const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found");