mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 07:53:00 +00:00
88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import { Alert } from "@/components/alert";
|
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
|
import { LoginPasskey } from "@/components/login-passkey";
|
|
import { UserAvatar } from "@/components/user-avatar";
|
|
import { getSessionCookieById } from "@/lib/cookies";
|
|
import { getServiceUrlFromHeaders } from "@/lib/service";
|
|
import { loadMostRecentSession } from "@/lib/session";
|
|
import { getBrandingSettings, getSession } from "@/lib/zitadel";
|
|
import { getLocale, getTranslations } from "next-intl/server";
|
|
import { headers } from "next/headers";
|
|
|
|
export default async function Page(props: {
|
|
searchParams: Promise<Record<string | number | symbol, string | undefined>>;
|
|
}) {
|
|
const searchParams = await props.searchParams;
|
|
const locale = getLocale();
|
|
const t = await getTranslations({ locale, namespace: "passkey" });
|
|
const tError = await getTranslations({ locale, namespace: "error" });
|
|
|
|
const { loginName, altPassword, requestId, organization, sessionId } =
|
|
searchParams;
|
|
|
|
const _headers = await headers();
|
|
const { serviceUrl } = getServiceUrlFromHeaders(_headers);
|
|
|
|
const sessionFactors = sessionId
|
|
? await loadSessionById(serviceUrl, sessionId, organization)
|
|
: await loadMostRecentSession({
|
|
serviceUrl,
|
|
|
|
sessionParams: { loginName, organization },
|
|
});
|
|
|
|
async function loadSessionById(
|
|
serviceUrl: string,
|
|
sessionId: string,
|
|
organization?: string,
|
|
) {
|
|
const recent = await getSessionCookieById({ sessionId, organization });
|
|
return getSession({
|
|
serviceUrl,
|
|
|
|
sessionId: recent.id,
|
|
sessionToken: recent.token,
|
|
}).then((response) => {
|
|
if (response?.session) {
|
|
return response.session;
|
|
}
|
|
});
|
|
}
|
|
|
|
const branding = await getBrandingSettings({
|
|
serviceUrl,
|
|
|
|
organization,
|
|
});
|
|
|
|
return (
|
|
<DynamicTheme branding={branding}>
|
|
<div className="flex flex-col items-center space-y-4">
|
|
<h1>{t("verify.title")}</h1>
|
|
|
|
{sessionFactors && (
|
|
<UserAvatar
|
|
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
|
|
displayName={sessionFactors.factors?.user?.displayName}
|
|
showDropdown
|
|
searchParams={searchParams}
|
|
></UserAvatar>
|
|
)}
|
|
<p className="ztdl-p mb-6 block">{t("verify.description")}</p>
|
|
|
|
{!(loginName || sessionId) && <Alert>{tError("unknownContext")}</Alert>}
|
|
|
|
{(loginName || sessionId) && (
|
|
<LoginPasskey
|
|
loginName={loginName}
|
|
sessionId={sessionId}
|
|
requestId={requestId}
|
|
altPassword={altPassword === "true"}
|
|
organization={organization}
|
|
/>
|
|
)}
|
|
</div>
|
|
</DynamicTheme>
|
|
);
|
|
}
|