feat: enrich Yandex OAuth with firstName/lastName/gender/avatar
This commit is contained in:
@@ -242,9 +242,18 @@ export async function registerOAuthSocialRoutes(fastify) {
|
|||||||
suggestedEmail: emailGuess || null,
|
suggestedEmail: emailGuess || null,
|
||||||
})
|
})
|
||||||
|
|
||||||
const dn = `${info.first_name ?? ''} ${info.last_name ?? ''}`.trim()
|
const updateData = {}
|
||||||
if (dn && !user.name) {
|
const displayName =
|
||||||
await prisma.user.update({ where: { id: user.id }, data: { name: dn } })
|
[info.first_name, info.last_name].filter(Boolean).join(' ').trim() || info.display_name || info.real_name
|
||||||
|
if (displayName && !user.displayName) updateData.displayName = displayName
|
||||||
|
if (info.first_name) updateData.firstName = info.first_name
|
||||||
|
if (info.last_name) updateData.lastName = info.last_name
|
||||||
|
if (info.sex === 'male' || info.sex === 'female') updateData.gender = info.sex
|
||||||
|
if (info.default_avatar_id && !info.is_avatar_empty) {
|
||||||
|
updateData.avatar = `https://avatars.yandex.net/get-yapic/${info.default_avatar_id}/islands-200`
|
||||||
|
}
|
||||||
|
if (Object.keys(updateData).length > 0) {
|
||||||
|
await prisma.user.update({ where: { id: user.id }, data: updateData })
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = await issueUserJwt(fastify, user.id, user.email)
|
const token = await issueUserJwt(fastify, user.id, user.email)
|
||||||
|
|||||||
Reference in New Issue
Block a user