2024-04-16 09:32:56 +02:00
|
|
|
import {
|
|
|
|
|
getBrandingSettings,
|
|
|
|
|
getLoginSettings,
|
|
|
|
|
getSession,
|
|
|
|
|
server,
|
|
|
|
|
} from "#/lib/zitadel";
|
2023-05-22 16:28:47 +02:00
|
|
|
import Alert from "#/ui/Alert";
|
2024-04-01 10:00:31 +02:00
|
|
|
import DynamicTheme from "#/ui/DynamicTheme";
|
2023-05-17 13:46:44 +02:00
|
|
|
import PasswordForm from "#/ui/PasswordForm";
|
2023-04-19 10:37:35 +02:00
|
|
|
import UserAvatar from "#/ui/UserAvatar";
|
2023-05-17 13:46:44 +02:00
|
|
|
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
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-03-25 13:39:23 +01:00
|
|
|
const { loginName, organization, promptPasswordless, authRequestId, alt } =
|
|
|
|
|
searchParams;
|
|
|
|
|
const sessionFactors = await loadSession(loginName, organization);
|
2023-04-03 13:39:51 +02:00
|
|
|
|
2024-03-25 13:39:23 +01:00
|
|
|
async function loadSession(loginName?: string, organization?: string) {
|
|
|
|
|
const recent = await getMostRecentCookieWithLoginname(
|
|
|
|
|
loginName,
|
|
|
|
|
organization
|
|
|
|
|
);
|
2023-05-22 16:28:47 +02:00
|
|
|
|
2023-05-24 16:41:06 +02:00
|
|
|
return getSession(server, recent.id, recent.token).then((response) => {
|
|
|
|
|
if (response?.session) {
|
|
|
|
|
return response.session;
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-05-22 16:28:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-04-01 10:00:31 +02:00
|
|
|
const branding = await getBrandingSettings(server, organization);
|
2024-04-16 09:32:56 +02:00
|
|
|
const loginSettings = await getLoginSettings(server, 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">
|
|
|
|
|
<h1>{sessionFactors?.factors?.user?.displayName ?? "Password"}</h1>
|
|
|
|
|
<p className="ztdl-p mb-6 block">Enter your password.</p>
|
|
|
|
|
|
|
|
|
|
{!sessionFactors && (
|
|
|
|
|
<div className="py-4">
|
|
|
|
|
<Alert>
|
|
|
|
|
Could not get the context of the user. Make sure to enter the
|
|
|
|
|
username first or provide a loginName as searchParam.
|
|
|
|
|
</Alert>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{sessionFactors && (
|
|
|
|
|
<UserAvatar
|
|
|
|
|
loginName={loginName ?? sessionFactors.factors?.user?.loginName}
|
|
|
|
|
displayName={sessionFactors.factors?.user?.displayName}
|
|
|
|
|
showDropdown
|
|
|
|
|
></UserAvatar>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<PasswordForm
|
|
|
|
|
loginName={loginName}
|
|
|
|
|
authRequestId={authRequestId}
|
|
|
|
|
organization={organization}
|
2024-04-16 09:32:56 +02:00
|
|
|
loginSettings={loginSettings}
|
2024-04-01 10:00:31 +02:00
|
|
|
promptPasswordless={promptPasswordless === "true"}
|
|
|
|
|
isAlternative={alt === "true"}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</DynamicTheme>
|
2023-04-03 13:39:51 +02:00
|
|
|
);
|
|
|
|
|
}
|