Skip to content

Commit 490105c

Browse files
committed
[backend] ... track last login, and joining time for register and login routes.
1 parent baa11f1 commit 490105c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: server/src/auth/auth.service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ export class AuthService {
2525
const match = await bcrypt.compare(password, user?.hashedPassword);
2626

2727
if (!match) {
28-
throw new UnauthorizedException();
28+
throw new UnauthorizedException("Password or email doesn't match");
2929
}
3030

31+
user.lastLogin = new Date();
32+
await user.save();
33+
3134
await this.mailer.sendTemplateMail({
3235
templateType: 'login',
3336
recipients: [email],

Diff for: server/src/users/users.service.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ export class UsersService {
6666
}
6767

6868
async create(createUserDto: CreateUserDto): Promise<User> {
69-
const createdUser = new this.model(createUserDto);
69+
const now = new Date();
70+
71+
const createdUser = new this.model({
72+
...createUserDto,
73+
lastLogin: now,
74+
joined: now,
75+
});
7076
return await createdUser.save();
7177
}
7278

@@ -87,7 +93,7 @@ export class UsersService {
8793
return String(user._id);
8894
}
8995

90-
async findOneByEmail(email: string): Promise<User | undefined> {
96+
async findOneByEmail(email: string): Promise<UserDocument | undefined> {
9197
return await this.model.findOne({ email: email });
9298
}
9399

0 commit comments

Comments
 (0)