import { getBrandingSettings, getSession, listAuthenticationMethodTypes, } from "@/lib/zitadel"; import Alert from "@/ui/Alert"; import ChooseSecondFactor from "@/ui/ChooseSecondFactor"; import DynamicTheme from "@/ui/DynamicTheme"; import UserAvatar from "@/ui/UserAvatar"; import { getMostRecentCookieWithLoginname, getSessionCookieById, } from "@/utils/cookies"; export default async function Page({ searchParams, }: { searchParams: Record; }) { const { loginName, checkAfter, authRequestId, organization, sessionId } = searchParams; const sessionFactors = sessionId ? await loadSessionById(sessionId, organization) : await loadSessionByLoginname(loginName, organization); async function loadSessionByLoginname( loginName?: string, organization?: string, ) { const recent = await getMostRecentCookieWithLoginname( loginName, organization, ); return getSession(recent.id, recent.token).then((response) => { if (response?.session && response.session.factors?.user?.id) { return listAuthenticationMethodTypes( response.session.factors.user.id, ).then((methods) => { return { factors: response.session?.factors, authMethods: methods.authMethodTypes ?? [], }; }); } }); } async function loadSessionById(sessionId: string, organization?: string) { const recent = await getSessionCookieById(sessionId, organization); return getSession(recent.id, recent.token).then((response) => { if (response?.session && response.session.factors?.user?.id) { return listAuthenticationMethodTypes( response.session.factors.user.id, ).then((methods) => { return { factors: response.session?.factors, authMethods: methods.authMethodTypes ?? [], }; }); } }); } const branding = await getBrandingSettings(organization); return (

Verify 2-Factor

Choose one of the following second factors.

{sessionFactors && ( )} {!(loginName || sessionId) && ( Provide your active session as loginName param )} {sessionFactors ? ( ) : ( No second factors available to setup. )}
); }