Skip to content

Commit

Permalink
[backend] ... track last login, and joining time for register and log…
Browse files Browse the repository at this point in the history
…in routes.
  • Loading branch information
Vinayak-Anand committed May 20, 2024
1 parent baa11f1 commit 490105c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export class AuthService {
const match = await bcrypt.compare(password, user?.hashedPassword);

if (!match) {
throw new UnauthorizedException();
throw new UnauthorizedException("Password or email doesn't match");
}

user.lastLogin = new Date();
await user.save();

await this.mailer.sendTemplateMail({
templateType: 'login',
recipients: [email],
Expand Down
10 changes: 8 additions & 2 deletions server/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,13 @@ export class UsersService {
}

async create(createUserDto: CreateUserDto): Promise<User> {
const createdUser = new this.model(createUserDto);
const now = new Date();

const createdUser = new this.model({
...createUserDto,
lastLogin: now,
joined: now,
});
return await createdUser.save();
}

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

async findOneByEmail(email: string): Promise<User | undefined> {
async findOneByEmail(email: string): Promise<UserDocument | undefined> {
return await this.model.findOne({ email: email });
}

Expand Down

0 comments on commit 490105c

Please sign in to comment.