email === null) { throw new BadRequestException('email is required'); } if ($request->password === null) { throw new BadRequestException('password is required'); } $user = $this->userRepo->findByEmail( new EmailAddress($request->email) ); if ($user === null) { throw new UnauthorizedException('invalid credentials'); } $passwordMatches = $this->passwordHasher->verify( $request->password, $user->getPasswordHash() ); if (!$passwordMatches) { throw new UnauthorizedException('invalid credentials'); } return $user; } }