mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 10:25:58 +00:00
handle errors more gracefully
This commit is contained in:
@@ -115,27 +115,12 @@ export default async function Page({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (options?.isCreationAllowed && options.isAutoCreation) {
|
|
||||||
const userId = await createUser(provider, idpInformation).catch(
|
|
||||||
(error) => {
|
|
||||||
return (
|
|
||||||
<DynamicTheme branding={branding}>
|
|
||||||
<div className="flex flex-col items-center space-y-4">
|
|
||||||
<h1>Register failed</h1>
|
|
||||||
<div className="w-full">
|
|
||||||
{
|
|
||||||
<Alert type={AlertType.ALERT}>
|
|
||||||
{JSON.stringify(error.message)}
|
|
||||||
</Alert>
|
|
||||||
}
|
}
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</DynamicTheme>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (userId) {
|
if (options?.isCreationAllowed && options.isAutoCreation) {
|
||||||
|
const newUser = await createUser(provider, idpInformation);
|
||||||
|
|
||||||
|
if (newUser) {
|
||||||
return (
|
return (
|
||||||
<DynamicTheme branding={branding}>
|
<DynamicTheme branding={branding}>
|
||||||
<div className="flex flex-col items-center space-y-4">
|
<div className="flex flex-col items-center space-y-4">
|
||||||
|
|||||||
@@ -23,21 +23,23 @@ export function idpTypeToSlug(idpType: IdentityProviderType) {
|
|||||||
|
|
||||||
// this maps the IDPInformation to the AddHumanUserRequest which is used when creating a user or linking a user (email)
|
// this maps the IDPInformation to the AddHumanUserRequest which is used when creating a user or linking a user (email)
|
||||||
// TODO: extend this object from a other file which can be overwritten by customers like map = { ...PROVIDER_MAPPING, ...customerMap }
|
// TODO: extend this object from a other file which can be overwritten by customers like map = { ...PROVIDER_MAPPING, ...customerMap }
|
||||||
export const PROVIDER_MAPPING: {
|
export type OIDC_USER = {
|
||||||
[provider: string]: (
|
|
||||||
rI: IDPInformation,
|
|
||||||
) => PartialMessage<AddHumanUserRequest>;
|
|
||||||
} = {
|
|
||||||
[idpTypeToSlug(IdentityProviderType.GOOGLE)]: (idp: IDPInformation) => {
|
|
||||||
const rawInfo = idp.rawInformation?.toJson() as {
|
|
||||||
User: {
|
User: {
|
||||||
email: string;
|
email: string;
|
||||||
name?: string;
|
name?: string;
|
||||||
given_name?: string;
|
given_name?: string;
|
||||||
family_name?: string;
|
family_name?: string;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const PROVIDER_MAPPING: {
|
||||||
|
[provider: string]: (
|
||||||
|
rI: IDPInformation,
|
||||||
|
) => PartialMessage<AddHumanUserRequest>;
|
||||||
|
} = {
|
||||||
|
[idpTypeToSlug(IdentityProviderType.GOOGLE)]: (idp: IDPInformation) => {
|
||||||
|
const rawInfo = idp.rawInformation?.toJson() as OIDC_USER;
|
||||||
|
console.log(rawInfo);
|
||||||
const idpLink: PartialMessage<IDPLink> = {
|
const idpLink: PartialMessage<IDPLink> = {
|
||||||
idpId: idp.idpId,
|
idpId: idp.idpId,
|
||||||
userId: idp.userId,
|
userId: idp.userId,
|
||||||
@@ -62,10 +64,16 @@ export const PROVIDER_MAPPING: {
|
|||||||
},
|
},
|
||||||
[idpTypeToSlug(IdentityProviderType.AZURE_AD)]: (idp: IDPInformation) => {
|
[idpTypeToSlug(IdentityProviderType.AZURE_AD)]: (idp: IDPInformation) => {
|
||||||
const rawInfo = idp.rawInformation?.toJson() as {
|
const rawInfo = idp.rawInformation?.toJson() as {
|
||||||
|
jobTitle: string;
|
||||||
mail: string;
|
mail: string;
|
||||||
|
mobilePhone: string;
|
||||||
|
preferredLanguage: string;
|
||||||
|
id: string;
|
||||||
displayName?: string;
|
displayName?: string;
|
||||||
givenName?: string;
|
givenName?: string;
|
||||||
surname?: string;
|
surname?: string;
|
||||||
|
officeLocation?: string;
|
||||||
|
userPrincipalName: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const idpLink: PartialMessage<IDPLink> = {
|
const idpLink: PartialMessage<IDPLink> = {
|
||||||
@@ -74,16 +82,18 @@ export const PROVIDER_MAPPING: {
|
|||||||
userName: idp.userName,
|
userName: idp.userName,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(rawInfo, rawInfo.userPrincipalName);
|
||||||
|
|
||||||
const req: PartialMessage<AddHumanUserRequest> = {
|
const req: PartialMessage<AddHumanUserRequest> = {
|
||||||
username: idp.userName,
|
username: idp.userName,
|
||||||
email: {
|
email: {
|
||||||
email: rawInfo?.mail,
|
email: rawInfo.mail || rawInfo.userPrincipalName || "",
|
||||||
verification: { case: "isVerified", value: true },
|
verification: { case: "isVerified", value: true },
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
displayName: rawInfo?.displayName ?? "",
|
displayName: rawInfo.displayName ?? "",
|
||||||
givenName: rawInfo?.givenName ?? "",
|
givenName: rawInfo.givenName ?? "",
|
||||||
familyName: rawInfo?.surname ?? "",
|
familyName: rawInfo.surname ?? "",
|
||||||
},
|
},
|
||||||
idpLinks: [idpLink],
|
idpLinks: [idpLink],
|
||||||
};
|
};
|
||||||
@@ -105,13 +115,13 @@ export const PROVIDER_MAPPING: {
|
|||||||
const req: PartialMessage<AddHumanUserRequest> = {
|
const req: PartialMessage<AddHumanUserRequest> = {
|
||||||
username: idp.userName,
|
username: idp.userName,
|
||||||
email: {
|
email: {
|
||||||
email: rawInfo?.email,
|
email: rawInfo.email,
|
||||||
verification: { case: "isVerified", value: true },
|
verification: { case: "isVerified", value: true },
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
displayName: rawInfo?.name ?? "",
|
displayName: rawInfo.name ?? "",
|
||||||
givenName: rawInfo?.name ?? "",
|
givenName: rawInfo.name ?? "",
|
||||||
familyName: rawInfo?.name ?? "",
|
familyName: rawInfo.name ?? "",
|
||||||
},
|
},
|
||||||
idpLinks: [idpLink],
|
idpLinks: [idpLink],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -391,12 +391,10 @@ export function addIDPLink(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUser(
|
export function createUser(provider: string, info: IDPInformation) {
|
||||||
provider: string,
|
|
||||||
info: IDPInformation,
|
|
||||||
): Promise<string> {
|
|
||||||
const userData = PROVIDER_MAPPING[provider](info);
|
const userData = PROVIDER_MAPPING[provider](info);
|
||||||
return userService.addHumanUser(userData, {}).then((resp) => resp.userId);
|
console.log("ud", userData);
|
||||||
|
return userService.addHumanUser(userData, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,7 +42,9 @@ export default function UserAvatar({
|
|||||||
loginName={loginName ?? ""}
|
loginName={loginName ?? ""}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className="ml-4 text-14px">{loginName}</span>
|
<span className="ml-4 text-14px max-w-[250px] text-ellipsis overflow-hidden">
|
||||||
|
{loginName}
|
||||||
|
</span>
|
||||||
<span className="flex-grow"></span>
|
<span className="flex-grow"></span>
|
||||||
{showDropdown && (
|
{showDropdown && (
|
||||||
<Link
|
<Link
|
||||||
|
|||||||
Reference in New Issue
Block a user