diff --git a/libs/common/src/auth/services/auth.service.ts b/libs/common/src/auth/services/auth.service.ts index 95d592e..bc25e0e 100644 --- a/libs/common/src/auth/services/auth.service.ts +++ b/libs/common/src/auth/services/auth.service.ts @@ -33,32 +33,33 @@ export class AuthService { const user = await this.userRepository.findOne({ where: { email, - region: regionUuid - ? { - uuid: regionUuid, - } - : undefined, + region: regionUuid ? { uuid: regionUuid } : undefined, }, relations: ['roleType'], }); + if (!user) { + throw new BadRequestException('Invalid credentials'); + } + if (!user.isUserVerified) { throw new BadRequestException('User is not verified'); } if (!user.isActive) { throw new BadRequestException('User is not active'); } - if (user) { - const passwordMatch = this.helperHashService.bcryptCompare( - pass, - user.password, - ); - if (passwordMatch) { - const { ...result } = user; - return result; - } + + const passwordMatch = await this.helperHashService.bcryptCompare( + pass, + user.password, + ); + if (!passwordMatch) { + throw new BadRequestException('Invalid credentials'); } - return null; + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + const { password, ...result } = user; + return result; } async createSession(data): Promise {