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