From 79d9ece2aeea894063be6d5ea08cae19d2e0576d Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 24 Apr 2026 13:21:02 +0300 Subject: [PATCH] add authenticate user use case --- app/User/UseCases/AuthenticateUser.php | 48 ++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/User/UseCases/AuthenticateUser.php diff --git a/app/User/UseCases/AuthenticateUser.php b/app/User/UseCases/AuthenticateUser.php new file mode 100644 index 0000000..56281b1 --- /dev/null +++ b/app/User/UseCases/AuthenticateUser.php @@ -0,0 +1,48 @@ +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 = password_verify( + $request->password, + $user->getPasswordHash() + ); + if (!$passwordMatches) { + throw new UnauthorizedException('invalid credentials'); + } + + return $user; + } +}