import { Alert } from "@/components/alert"; 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, getLoginSettings, getSession, } from "@/lib/zitadel"; import { getLocale, getTranslations } from "next-intl/server"; import { headers } from "next/headers"; export default async function Page(props: { searchParams: Promise>; params: Promise>; }) { const params = await props.params; const searchParams = await props.searchParams; const locale = getLocale(); const t = await getTranslations({ locale, namespace: "otp" }); const tError = await getTranslations({ locale, namespace: "error" }); const _headers = await headers(); const instanceUrl = getApiUrlOfHeaders(_headers); const host = instanceUrl; if (!host || typeof host !== "string") { throw new Error("No host found"); } const { loginName, // send from password page userId, // send from email link authRequestId, sessionId, organization, code, submit, } = searchParams; const { method } = params; const session = sessionId ? await loadSessionById(host, sessionId, organization) : await loadMostRecentSession({ host, sessionParams: { loginName, organization }, }); async function loadSessionById( host: string, sessionId: string, organization?: string, ) { const recent = await getSessionCookieById({ sessionId, organization }); return getSession({ host, sessionId: recent.id, sessionToken: recent.token, }).then((response) => { if (response?.session) { return response.session; } }); } // email links do not come with organization, thus we need to use the session's organization const branding = await getBrandingSettings({ host, organization: organization ?? session?.factors?.user?.organizationId, }); const loginSettings = await getLoginSettings({ host, organization: organization ?? session?.factors?.user?.organizationId, }); return (

{t("verify.title")}

{method === "time-based" && (

{t("verify.totpDescription")}

)} {method === "sms" && (

{t("verify.smsDescription")}

)} {method === "email" && (

{t("verify.emailDescription")}

)} {!session && (
{tError("unknownContext")}
)} {session && ( )} {method && session && ( )}
); }