Files
zitadel/apps/login/src/app/(login)/loginname/page.tsx

90 lines
2.9 KiB
TypeScript
Raw Normal View History

2024-09-26 22:50:55 -04:00
import { DynamicTheme } from "@/components/dynamic-theme";
import { SignInWithIdp } from "@/components/sign-in-with-idp";
import { UsernameForm } from "@/components/username-form";
2025-01-28 09:47:35 +01:00
import { getApiUrlOfHeaders } from "@/lib/service";
2024-03-15 17:21:21 +01:00
import {
2024-11-29 13:38:56 +01:00
getActiveIdentityProviders,
2024-04-01 10:00:31 +02:00
getBrandingSettings,
2024-11-12 14:41:34 +01:00
getDefaultOrg,
2024-03-15 17:21:21 +01:00
getLoginSettings,
2024-05-13 16:17:12 -04:00
} from "@/lib/zitadel";
2024-11-12 14:41:34 +01:00
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
2024-10-09 09:56:45 +02:00
import { getLocale, getTranslations } from "next-intl/server";
2025-01-15 09:57:24 +01:00
import { headers } from "next/headers";
2024-03-15 17:21:21 +01:00
2024-11-22 11:27:37 +01:00
export default async function Page(props: {
searchParams: Promise<Record<string | number | symbol, string | undefined>>;
}) {
2024-11-22 11:25:03 +01:00
const searchParams = await props.searchParams;
2024-10-09 09:56:45 +02:00
const locale = getLocale();
const t = await getTranslations({ locale, namespace: "loginname" });
2024-10-08 14:32:06 +02:00
const loginName = searchParams?.loginName;
const authRequestId = searchParams?.authRequestId;
const organization = searchParams?.organization;
2025-01-09 13:38:00 +01:00
const suffix = searchParams?.suffix;
const submit: boolean = searchParams?.submit === "true";
2025-01-28 09:47:35 +01:00
const _headers = await headers();
const instanceUrl = getApiUrlOfHeaders(_headers);
const host = instanceUrl;
2025-01-15 09:57:24 +01:00
if (!host || typeof host !== "string") {
throw new Error("No host found");
}
let defaultOrganization;
2024-11-12 14:41:34 +01:00
if (!organization) {
2025-01-15 09:57:24 +01:00
const org: Organization | null = await getDefaultOrg({ host });
2024-11-12 16:54:42 +01:00
if (org) {
defaultOrganization = org.id;
2024-11-12 14:41:34 +01:00
}
}
2025-01-15 09:57:24 +01:00
const loginSettings = await getLoginSettings({
host,
organization: organization ?? defaultOrganization,
});
2025-01-15 09:57:24 +01:00
const contextLoginSettings = await getLoginSettings({ host, organization });
2025-01-09 13:38:00 +01:00
2025-01-15 09:57:24 +01:00
const identityProviders = await getActiveIdentityProviders({
host,
orgId: organization ?? defaultOrganization,
}).then((resp) => {
2024-11-29 13:38:56 +01:00
return resp.identityProviders;
});
2025-01-15 09:57:24 +01:00
const branding = await getBrandingSettings({
host,
organization: organization ?? defaultOrganization,
});
2023-06-29 19:06:30 +02:00
2024-04-01 10:00:31 +02:00
return (
<DynamicTheme branding={branding}>
<div className="flex flex-col items-center space-y-4">
2024-10-08 14:32:06 +02:00
<h1>{t("title")}</h1>
<p className="ztdl-p">{t("description")}</p>
2024-03-15 17:21:21 +01:00
2024-04-01 10:00:31 +02:00
<UsernameForm
loginName={loginName}
2024-03-28 10:04:41 +01:00
authRequestId={authRequestId}
organization={organization} // stick to "organization" as we still want to do user discovery based on the searchParams not the default organization, later the organization is determined by the found user
2025-01-09 13:38:00 +01:00
loginSettings={contextLoginSettings}
suffix={suffix}
2024-04-01 10:00:31 +02:00
submit={submit}
2024-07-17 16:54:25 +02:00
allowRegister={!!loginSettings?.allowRegister}
2024-08-08 10:29:17 +02:00
>
2024-11-29 13:38:56 +01:00
{identityProviders && (
2024-09-26 22:50:55 -04:00
<SignInWithIdp
2024-08-08 10:29:17 +02:00
identityProviders={identityProviders}
authRequestId={authRequestId}
2024-12-16 11:15:01 +01:00
organization={organization}
2024-09-26 22:50:55 -04:00
></SignInWithIdp>
2024-08-08 10:29:17 +02:00
)}
</UsernameForm>
2024-04-01 10:00:31 +02:00
</div>
</DynamicTheme>
2023-06-29 19:06:30 +02:00
);
2023-04-03 13:39:51 +02:00
}