mirror of
https://github.com/vernu/textbee.git
synced 2026-02-20 15:44:31 -05:00
fix(api): fix signin with google not updating user data properly
This commit is contained in:
@@ -65,23 +65,24 @@ export class AuthService {
|
||||
user = await this.usersService.create({
|
||||
name,
|
||||
email,
|
||||
googleId,
|
||||
avatar: picture,
|
||||
lastLoginAt: new Date(),
|
||||
})
|
||||
} else {
|
||||
user.googleId = googleId
|
||||
|
||||
if (!user.name) {
|
||||
user.name = name
|
||||
}
|
||||
if (!user.avatar) {
|
||||
user.avatar = picture
|
||||
}
|
||||
user.lastLoginAt = new Date()
|
||||
await user.save()
|
||||
}
|
||||
|
||||
if (user.googleId !== googleId) {
|
||||
user.googleId = googleId
|
||||
}
|
||||
|
||||
if (user.name !== name) {
|
||||
user.name = name
|
||||
}
|
||||
|
||||
if (user.avatar !== picture) {
|
||||
user.avatar = picture
|
||||
}
|
||||
|
||||
user.lastLoginAt = new Date()
|
||||
await user.save()
|
||||
|
||||
const payload = { email: user.email, sub: user._id }
|
||||
return {
|
||||
accessToken: this.jwtService.sign(payload),
|
||||
@@ -107,9 +108,11 @@ export class AuthService {
|
||||
const user = await this.usersService.create({
|
||||
...userData,
|
||||
password: hashedPassword,
|
||||
lastLoginAt: new Date(),
|
||||
})
|
||||
|
||||
user.lastLoginAt = new Date()
|
||||
await user.save()
|
||||
|
||||
const payload = { email: user.email, sub: user._id }
|
||||
|
||||
return {
|
||||
|
||||
@@ -15,8 +15,15 @@ export class UsersService {
|
||||
return await this.userModel.find()
|
||||
}
|
||||
|
||||
async create(userData: any) {
|
||||
const { name, email, password } = userData
|
||||
async create({
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
}: {
|
||||
name: string
|
||||
email: string
|
||||
password?: string
|
||||
}) {
|
||||
if (await this.findOne({ email })) {
|
||||
throw new HttpException(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user