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" ;
2024-03-15 17:21:21 +01:00
import {
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-04-07 03:56:46 -04:00
settingsService ,
2024-05-13 16:17:12 -04:00
} from "@/lib/zitadel" ;
2024-08-06 09:34:45 +02:00
import { makeReqCtx } from "@zitadel/client/v2" ;
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" ;
2024-03-15 17:21:21 +01:00
2024-04-07 03:56:46 -04:00
function getIdentityProviders ( orgId? : string ) {
2024-03-15 17:21:21 +01:00
return settingsService
2024-04-07 03:56:46 -04:00
. getActiveIdentityProviders ( { ctx : makeReqCtx ( orgId ) } , { } )
. then ( ( resp ) = > {
2024-03-15 17:21:21 +01:00
return resp . identityProviders ;
} ) ;
}
2023-06-29 14:54:07 +02:00
export default async function Page ( {
searchParams ,
} : {
searchParams : Record < string | number | symbol , string | undefined > ;
} ) {
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
2023-06-29 14:54:07 +02:00
const loginName = searchParams ? . loginName ;
2023-08-21 15:14:12 +02:00
const authRequestId = searchParams ? . authRequestId ;
2024-11-12 15:30:57 +01:00
const organization = searchParams ? . organization ;
2023-07-03 17:05:55 +02:00
const submit : boolean = searchParams ? . submit === "true" ;
2023-06-29 14:54:07 +02:00
2024-11-12 15:30:57 +01:00
let defaultOrganization ;
2024-11-12 14:41:34 +01:00
if ( ! organization ) {
2024-11-14 10:35:36 +01:00
const org : Organization | null = await getDefaultOrg ( ) ;
2024-11-12 16:54:42 +01:00
if ( org ) {
2024-11-12 15:30:57 +01:00
defaultOrganization = org . id ;
2024-11-12 14:41:34 +01:00
}
}
2024-03-15 17:21:21 +01:00
const host = process . env . VERCEL_URL
? ` https:// ${ process . env . VERCEL_URL } `
: "http://localhost:3000" ;
2023-06-29 14:54:07 +02:00
2024-11-12 15:30:57 +01:00
const loginSettings = await getLoginSettings (
organization ? ? defaultOrganization ,
) ;
const identityProviders = await getIdentityProviders (
organization ? ? defaultOrganization ,
) ;
const branding = await getBrandingSettings (
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 }
2024-11-12 15:30:57 +01:00
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
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-12 14:41:34 +01:00
{ identityProviders && process . env . ZITADEL_API_URL && (
2024-09-26 22:50:55 -04:00
< SignInWithIdp
2024-08-08 10:29:17 +02:00
host = { host }
identityProviders = { identityProviders }
authRequestId = { authRequestId }
2024-11-12 15:30:57 +01:00
organization = { organization ? ? defaultOrganization } // use the organization from the searchParams here otherwise fallback to the default 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
}