2024-09-26 22:50:55 -04:00
|
|
|
import { Alert } from "@/components/alert";
|
|
|
|
|
import { DynamicTheme } from "@/components/dynamic-theme";
|
|
|
|
|
import { PasswordForm } from "@/components/password-form";
|
|
|
|
|
import { UserAvatar } from "@/components/user-avatar";
|
2024-09-04 15:47:29 +02:00
|
|
|
import { loadMostRecentSession } from "@/lib/session";
|
2024-09-05 14:02:08 +02:00
|
|
|
import { getBrandingSettings, getLoginSettings } from "@/lib/zitadel";
|
2024-09-16 11:36:44 +02:00
|
|
|
import { PasskeysType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb";
|
2024-10-09 14:03:01 +02:00
|
|
|
import { getLocale, getTranslations } from "next-intl/server";
|
2023-04-03 13:39:51 +02:00
|
|
|
|
2023-05-24 14:28:55 +02:00
|
|
|
export default async function Page({
|
|
|
|
|
searchParams,
|
|
|
|
|
}: {
|
|
|
|
|
searchParams: Record<string | number | symbol, string | undefined>;
|
|
|
|
|
}) {
|
2024-10-09 14:03:01 +02:00
|
|
|
const locale = getLocale();
|
|
|
|
|
const t = await getTranslations({ locale, namespace: "password" });
|
2024-10-17 16:35:30 +02:00
|
|
|
const tError = await getTranslations({ locale, namespace: "error" });
|
2024-10-09 14:03:01 +02:00
|
|
|
|
2024-09-16 11:36:44 +02:00
|
|
|
const { loginName, organization, authRequestId, alt } = searchParams;
|
2023-04-03 13:39:51 +02:00
|
|
|
|
2024-09-18 14:13:04 +02:00
|
|
|
// also allow no session to be found (ignoreUnkownUsername)
|
|
|
|
|
let sessionFactors;
|
|
|
|
|
try {
|
|
|
|
|
sessionFactors = await loadMostRecentSession({
|
|
|
|
|
loginName,
|
|
|
|
|
organization,
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// ignore error to continue to show the password form
|
|
|
|
|
console.warn(error);
|
|
|
|
|
}
|
2023-05-22 16:28:47 +02:00
|
|
|
|
2024-04-07 03:56:46 -04:00
|
|
|
const branding = await getBrandingSettings(organization);
|
|
|
|
|
const loginSettings = await getLoginSettings(organization);
|
2024-04-01 10:00:31 +02:00
|
|
|
|
2023-04-03 13:39:51 +02:00
|
|
|
return (
|
2024-04-01 10:00:31 +02:00
|
|
|
<DynamicTheme branding={branding}>
|
|
|
|
|
<div className="flex flex-col items-center space-y-4">
|
2024-10-16 16:29:48 +02:00
|
|
|
<h1>
|
|
|
|
|
{sessionFactors?.factors?.user?.displayName ?? t("verify.title")}
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="ztdl-p mb-6 block">{t("verify.description")}</p>
|
2024-04-01 10:00:31 +02:00
|
|
|
|
2024-09-18 14:13:04 +02:00
|
|
|
{/* show error only if usernames should be shown to be unknown */}
|
|
|
|
|
{(!sessionFactors || !loginName) &&
|
|
|
|
|
!loginSettings?.ignoreUnknownUsernames && (
|
|
|
|
|
<div className="py-4">
|
2024-10-17 16:35:30 +02:00
|
|
|
<Alert>{tError("unknownContext")}</Alert>
|
2024-09-18 14:13:04 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
2024-04-01 10:00:31 +02:00
|
|
|
|
|
|
|
|
{sessionFactors && (
|
|
|
|
|
<UserAvatar
|
|
|
|
|
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
|
|
|
|
|
displayName={sessionFactors.factors?.user?.displayName}
|
|
|
|
|
showDropdown
|
2024-05-03 10:09:18 +02:00
|
|
|
searchParams={searchParams}
|
2024-04-01 10:00:31 +02:00
|
|
|
></UserAvatar>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-09-03 14:15:42 +02:00
|
|
|
{loginName && (
|
|
|
|
|
<PasswordForm
|
|
|
|
|
loginName={loginName}
|
|
|
|
|
authRequestId={authRequestId}
|
|
|
|
|
organization={organization}
|
|
|
|
|
loginSettings={loginSettings}
|
2024-09-16 11:36:44 +02:00
|
|
|
promptPasswordless={
|
|
|
|
|
loginSettings?.passkeysType === PasskeysType.ALLOWED
|
|
|
|
|
}
|
2024-09-03 14:15:42 +02:00
|
|
|
isAlternative={alt === "true"}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-04-01 10:00:31 +02:00
|
|
|
</div>
|
|
|
|
|
</DynamicTheme>
|
2023-04-03 13:39:51 +02:00
|
|
|
);
|
|
|
|
|
}
|