Skip to content

Commit e156a09

Browse files
committed
fix: refine profile field population for ZITADEL validation by ensuring fallback values for givenName and familyName are correctly applied
1 parent 6e7f381 commit e156a09

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

  • apps/login/src/app/(main)/(boxed)/idp/[provider]/success

apps/login/src/app/(main)/(boxed)/idp/[provider]/success/page.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,29 +101,30 @@ export default async function Page(props: {
101101
const { idpInformation, userId } = intent;
102102
let { addHumanUser } = intent;
103103

104-
// ensure mandatory profile fields are populated to satisfy ZITADEL validation (e.g., GitHub may not provide givenName)
104+
// ensure mandatory profile fields are populated to satisfy ZITADEL validation, as GitHub does not provide givenName
105+
// and familyName
105106
if (addHumanUser) {
106-
const givenNameMissing =
107-
!addHumanUser.profile?.givenName ||
108-
addHumanUser.profile.givenName.length === 0;
109-
const familyNameMissing =
110-
!addHumanUser.profile?.familyName ||
111-
addHumanUser.profile.familyName.length === 0;
112-
113-
if (givenNameMissing || familyNameMissing) {
114-
addHumanUser = {
115-
...addHumanUser,
116-
profile: {
117-
...addHumanUser.profile,
118-
givenName: givenNameMissing
119-
? (idpInformation?.userName ?? "user")
120-
: addHumanUser.profile?.givenName,
121-
familyName: familyNameMissing
122-
? (idpInformation?.userName ?? "user")
123-
: addHumanUser.profile?.familyName,
124-
},
125-
} as typeof addHumanUser;
107+
const profile: any = addHumanUser.profile ?? {};
108+
let { givenName, familyName } = profile;
109+
110+
const fallback = idpInformation?.userName ?? "user";
111+
112+
if (!givenName || givenName.trim().length === 0) {
113+
givenName = fallback.slice(0, 200);
126114
}
115+
116+
if (!familyName || familyName.trim().length === 0) {
117+
familyName = fallback.slice(0, 200);
118+
}
119+
120+
addHumanUser = {
121+
...addHumanUser,
122+
profile: {
123+
...profile,
124+
givenName,
125+
familyName,
126+
},
127+
} as typeof addHumanUser;
127128
}
128129

129130
if (!idpInformation) {

0 commit comments

Comments
 (0)