host change everywhere

This commit is contained in:
Max Peintner
2025-01-28 09:47:35 +01:00
parent 44bb8588de
commit d378c6504e
35 changed files with 187 additions and 52 deletions

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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<Record<string | number | symbol, string | undefined>>;
}) {
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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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<any> }) {
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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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<any> }) {
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");

View File

@@ -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");

View File

@@ -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<Session> {
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<Session> {
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");

View File

@@ -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" };

View File

@@ -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" };

View File

@@ -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" };

View File

@@ -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");

View File

@@ -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<RegisterPasskeyResponse> {
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" };

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");

View File

@@ -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");