perf: 完善新用户引导

This commit is contained in:
richarjiang
2026-04-06 15:50:22 +08:00
parent 66d47ec162
commit f8268cb6f6
15 changed files with 483 additions and 119 deletions

View File

@@ -8,6 +8,7 @@ import { WechatService } from './wechat.service'
export interface LoginResult {
token: string
user: User
isNewUser: boolean
}
export interface JwtPayload {
@@ -69,6 +70,8 @@ export class AuthService {
where: { openid },
})
const isNewUser = existingUser === null
const user =
existingUser ??
(await this.prisma.user.create({
@@ -89,7 +92,7 @@ export class AuthService {
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: updated }
return { token, user: updated, isNewUser: false }
}
sessionKeyStore.set(user.id, sessionKey)
@@ -97,7 +100,7 @@ export class AuthService {
const payload: JwtPayload = { sub: user.id, role: user.role as UserRole }
const token = this.jwtService.sign(payload)
return { token, user }
return { token, user, isNewUser }
}
async bindPhone(