From 7556c512bae802a4058218e4b078feab00eca8c7 Mon Sep 17 00:00:00 2001 From: peintnermax Date: Wed, 21 Aug 2024 14:22:52 +0200 Subject: [PATCH] lint, cleanup --- .../app/(login)/idp/[provider]/failure/page.tsx | 12 +++++++++++- apps/login/src/lib/idp.ts | 14 ++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx b/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx index 166c6b03ab8..2be2c54b019 100644 --- a/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx +++ b/apps/login/src/app/(login)/idp/[provider]/failure/page.tsx @@ -1,5 +1,15 @@ -import { getBrandingSettings, PROVIDER_NAME_MAPPING } from "@/lib/zitadel"; +import { getBrandingSettings } from "@/lib/zitadel"; import DynamicTheme from "@/ui/DynamicTheme"; +import { IdentityProviderType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb"; + +// This configuration shows the given name in the respective IDP button as fallback +const PROVIDER_NAME_MAPPING: { + [provider: string]: string; +} = { + [IdentityProviderType.GOOGLE]: "Google", + [IdentityProviderType.GITHUB]: "GitHub", + [IdentityProviderType.AZURE_AD]: "Microsoft", +}; export default async function Page({ searchParams, diff --git a/apps/login/src/lib/idp.ts b/apps/login/src/lib/idp.ts index cffa55d7cc9..fe4d98a58af 100644 --- a/apps/login/src/lib/idp.ts +++ b/apps/login/src/lib/idp.ts @@ -3,6 +3,7 @@ import { IDPInformation, IDPLink } from "@zitadel/proto/zitadel/user/v2/idp_pb"; import { IdentityProviderType } from "@zitadel/proto/zitadel/settings/v2/login_settings_pb"; import { PartialMessage } from "@zitadel/client"; +// This maps the IdentityProviderType to a slug which is used in the /success and /failure routes export function idpTypeToSlug(idpType: IdentityProviderType) { switch (idpType) { case IdentityProviderType.GITHUB: @@ -20,14 +21,7 @@ export function idpTypeToSlug(idpType: IdentityProviderType) { } } -export const PROVIDER_NAME_MAPPING: { - [provider: string]: string; -} = { - [IdentityProviderType.GOOGLE]: "Google", - [IdentityProviderType.GITHUB]: "GitHub", - [IdentityProviderType.AZURE_AD]: "Microsoft", -}; - +// this maps the IDPInformation to the AddHumanUserRequest which is used when creating a user or linking a user (email) export const PROVIDER_MAPPING: { [provider: string]: ( rI: IDPInformation, @@ -63,6 +57,7 @@ export const PROVIDER_MAPPING: { }, idpLinks: [idpLink], }; + return req; }, [idpTypeToSlug(IdentityProviderType.AZURE_AD)]: (idp: IDPInformation) => { @@ -101,11 +96,13 @@ export const PROVIDER_MAPPING: { email: string; name: string; }; + const idpLink: PartialMessage = { idpId: idp.idpId, userId: idp.userId, userName: idp.userName, }; + const req: PartialMessage = { username: idp.userName, email: { @@ -120,6 +117,7 @@ export const PROVIDER_MAPPING: { }, idpLinks: [idpLink], }; + return req; }, };