import { Alert } from "@/components/alert"; import { DynamicTheme } from "@/components/dynamic-theme"; import { UserAvatar } from "@/components/user-avatar"; import { VerifyForm } from "@/components/verify-form"; import { VerifyRedirectButton } from "@/components/verify-redirect-button"; import { resendVerification } from "@/lib/server/verify"; import { loadMostRecentSession } from "@/lib/session"; import { getBrandingSettings, getUserByID, listAuthenticationMethodTypes, } from "@/lib/zitadel"; import { HumanUser, User } from "@zitadel/proto/zitadel/user/v2/user_pb"; import { AuthenticationMethodType } from "@zitadel/proto/zitadel/user/v2/user_service_pb"; import { getLocale, getTranslations } from "next-intl/server"; export default async function Page(props: { searchParams: Promise }) { const searchParams = await props.searchParams; const locale = getLocale(); const t = await getTranslations({ locale, namespace: "verify" }); const tError = await getTranslations({ locale, namespace: "error" }); const { userId, loginName, code, organization, authRequestId, invite, skipsend, } = searchParams; const branding = await getBrandingSettings(organization); let sessionFactors; let user: User | undefined; let human: HumanUser | undefined; let id: string | undefined; if ("loginName" in searchParams) { sessionFactors = await loadMostRecentSession({ loginName, organization, }); if (!skipsend && sessionFactors?.factors?.user?.id) { await resendVerification({ userId: sessionFactors?.factors?.user?.id, isInvite: invite === "true", }).catch((error) => { console.error("Could not resend verification email", error); throw Error("Could not request email"); }); } } else if ("userId" in searchParams && userId) { if (!skipsend) { await resendVerification({ userId, isInvite: invite === "true", }).catch((error) => { console.error("Could not resend verification email", error); throw Error("Could not request email"); }); } const userResponse = await getUserByID(userId); if (userResponse) { user = userResponse.user; if (user?.type.case === "human") { human = user.type.value as HumanUser; } } } id = userId ?? sessionFactors?.factors?.user?.id; let authMethods: AuthenticationMethodType[] | null = null; if (human?.email?.isVerified) { const authMethodsResponse = await listAuthenticationMethodTypes(userId); if (authMethodsResponse.authMethodTypes) { authMethods = authMethodsResponse.authMethodTypes; } } const params = new URLSearchParams({ userId: userId, initial: "true", // defines that a code is not required and is therefore not shown in the UI }); if (loginName) { params.set("loginName", loginName); } if (organization) { params.set("organization", organization); } if (authRequestId) { params.set("authRequestId", authRequestId); } return (

{t("verify.title")}

{t("verify.description")}

{!id && ( <>

{t("verify.title")}

{t("verify.description")}

{tError("unknownContext")}
)} {sessionFactors ? ( ) : ( user && ( ) )} {id && (human?.email?.isVerified ? ( // show page for already verified users ) : ( // check if auth methods are set ))}
); }