perf: 完善新用户引导
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user