Skip to content

Commit

Permalink
fix: status code when wrong email and password (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Notekunn authored Jan 15, 2023
1 parent 26e897d commit 46d715b
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GetUserByEmailQuery } from '@modules/users/cqrs/queries/impl/get-user-by-email.query'
import { NotFoundException } from '@nestjs/common'
import { BadRequestException } from '@nestjs/common'
import { CommandHandler, ICommandHandler, QueryBus } from '@nestjs/cqrs'
import { UtilService } from '@shared/utils.service'

Expand All @@ -13,13 +13,13 @@ export class LoginByEmailCommandHandler implements ICommandHandler<LoginByEmailC
const { email, password } = _command
const user = await this.queryBus.execute(new GetUserByEmailQuery(email))
if (!user) {
throw new NotFoundException('error.userNotFound')
throw new BadRequestException('error.userPasswordNotMatching')
}

const isPasswordMatching = await UtilService.validateHash(password, user.password)

if (!isPasswordMatching) {
throw new NotFoundException('error.passwordNotCorrect')
throw new BadRequestException('error.userPasswordNotMatching')
}

return user
Expand Down

0 comments on commit 46d715b

Please sign in to comment.