Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 does not match');
}

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

await this.mailer.sendTemplateMail({
templateType: 'login',
recipients: [email],
Expand Down
9 changes: 7 additions & 2 deletions server/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ 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 +92,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