perf: 优化订阅刷新逻辑
This commit is contained in:
@@ -126,30 +126,26 @@ export class AuthService {
|
||||
})
|
||||
|
||||
const isNewUser = existingUser === null
|
||||
const now = new Date()
|
||||
|
||||
const user =
|
||||
existingUser ??
|
||||
(await this.prisma.user.create({
|
||||
data: {
|
||||
openid,
|
||||
...(unionid !== undefined && { unionid }),
|
||||
nickname: nickname || generateDefaultNickname(this.randomFn),
|
||||
...(avatarUrl && { avatarUrl }),
|
||||
adminBookingSubscriptionCount: 0,
|
||||
},
|
||||
}))
|
||||
|
||||
// Update avatar for existing users if new avatar is provided
|
||||
if (existingUser && avatarUrl) {
|
||||
const updated = await this.prisma.user.update({
|
||||
where: { id: existingUser.id },
|
||||
data: { avatarUrl, ...(nickname && { nickname }) },
|
||||
})
|
||||
sessionKeyStore.set(updated.id, sessionKey)
|
||||
const payload: JwtPayload = { sub: updated.id, role: updated.role as UserRole }
|
||||
const token = this.jwtService.sign(payload)
|
||||
return { token, user: await this.mapLoginUser(updated), isNewUser: false }
|
||||
}
|
||||
const user = isNewUser
|
||||
? await this.prisma.user.create({
|
||||
data: {
|
||||
openid,
|
||||
...(unionid !== undefined && { unionid }),
|
||||
nickname: nickname || generateDefaultNickname(this.randomFn),
|
||||
...(avatarUrl && { avatarUrl }),
|
||||
adminBookingSubscriptionCount: 0,
|
||||
lastLoginAt: now,
|
||||
},
|
||||
})
|
||||
: await this.prisma.user.update({
|
||||
where: { id: existingUser.id },
|
||||
data: {
|
||||
lastLoginAt: now,
|
||||
...(avatarUrl && { avatarUrl, ...(nickname && { nickname }) }),
|
||||
},
|
||||
})
|
||||
|
||||
sessionKeyStore.set(user.id, sessionKey)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user