chore(api): save last login at

This commit is contained in:
isra el
2024-04-24 14:11:19 +03:00
parent 28d40e05b4
commit d2abc28a1a
2 changed files with 13 additions and 1 deletions

View File

@@ -43,6 +43,9 @@ export class AuthService {
)
}
user.lastLoginAt = new Date()
await user.save()
const payload = { email: user.email, sub: user._id }
return {
accessToken: this.jwtService.sign(payload),
@@ -64,6 +67,7 @@ export class AuthService {
email,
googleId,
avatar: picture,
lastLoginAt: new Date(),
})
} else {
user.googleId = googleId
@@ -74,6 +78,7 @@ export class AuthService {
if (!user.avatar) {
user.avatar = picture
}
user.lastLoginAt = new Date()
await user.save()
}
@@ -89,6 +94,7 @@ export class AuthService {
const user = await this.usersService.create({
...userData,
password: hashedPassword,
lastLoginAt: new Date(),
})
const payload = { email: user.email, sub: user._id }
@@ -223,7 +229,10 @@ export class AuthService {
user,
method,
url: url.split('?')[0],
ip,
ip:
request.headers['x-forwarded-for'] ||
request.connection.remoteAddress ||
ip,
userAgent,
})
.catch((e) => {

View File

@@ -28,6 +28,9 @@ export class User {
@Prop({ type: String, default: UserRole.REGULAR })
role: string
@Prop({ type: Date })
lastLoginAt: Date
}
export const UserSchema = SchemaFactory.createForClass(User)