mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-11 20:27:43 +02:00
fix(account): handle single-word names in OIDC and GitHub auth providers (#10631)
When a user's name has no spaces (common for CJK names like "西门吹雪"),
name.split(' ') returns a single-element array so the last name
destructures as undefined, causing a PostgreSQL NOT NULL constraint
violation on the last_name column.
- openid: prefer standard OIDC given_name/family_name claims when
available, fall back to splitting name with safe slice(1).join()
- github: same split fix using displayName ?? username
- loginOrSignUpWithProvider: add ?? '' defensive fallback at insertOne
to guard against any undefined last name reaching the DB
Fixes #10628
Signed-off-by: SaiVaraprasad Medapati <varaprasadreddy9676@gmail.com>
This commit is contained in:
@@ -57,7 +57,9 @@ export function registerGithub (
|
||||
},
|
||||
async (ctx, next) => {
|
||||
const email = ctx.state.user.emails?.[0]?.value
|
||||
const [first, last] = ctx.state.user.displayName?.split(' ') ?? [ctx.state.user.username, '']
|
||||
const nameParts = (ctx.state.user.displayName ?? ctx.state.user.username ?? '').split(' ')
|
||||
const first: string = nameParts[0] ?? ''
|
||||
const last: string = nameParts.slice(1).join(' ')
|
||||
const db = await dbPromise
|
||||
|
||||
const redirectUrl = await handleProviderAuth(
|
||||
|
||||
@@ -87,7 +87,9 @@ export function registerOpenid (
|
||||
async (ctx, next) => {
|
||||
const email = ctx.state.user.email
|
||||
const verifiedEmail = (ctx.state.user.email_verified as boolean) ? email : ''
|
||||
const [first, last] = ctx.state.user.name?.split(' ') ?? [ctx.state.user.username, '']
|
||||
const nameParts = (ctx.state.user.name ?? ctx.state.user.username ?? '').split(' ')
|
||||
const first: string = ctx.state.user.given_name ?? nameParts[0] ?? ''
|
||||
const last: string = ctx.state.user.family_name ?? nameParts.slice(1).join(' ')
|
||||
|
||||
const db = await dbPromise
|
||||
const redirectUrl = await handleProviderAuth(
|
||||
|
||||
@@ -1547,7 +1547,7 @@ export async function loginOrSignUpWithProvider (
|
||||
return null
|
||||
}
|
||||
|
||||
personUuid = await db.person.insertOne({ firstName: first, lastName: last })
|
||||
personUuid = await db.person.insertOne({ firstName: first, lastName: last ?? '' })
|
||||
}
|
||||
|
||||
if (personUuid == null) {
|
||||
|
||||
Reference in New Issue
Block a user