From 0657622eab53c510667d028ae5a812cc14d68c7a Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 12 Dec 2023 18:57:03 -0500 Subject: [PATCH] - Fixed a bug where given entity would failed it's loading with an error --- src/Lib/Authenticate.php | 9 +++++++-- src/Middleware/PostRequestAuthenticationMiddleware.php | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index 8280662..0a97e02 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -27,8 +27,13 @@ class Authenticate { public function rememberMe() : ? UserInterface { $logUser = function(? int $id) { - if ( $id === null || null === ( $user = $this->user::repository()->loadFromPk($id) ) ) { - throw new \InvalidArgumentException(sprintf("User having id '%s' was not found.", $id)); + try { + if ($id === null || null === ($user = $this->user::repository()->loadFromPk($id))) { + throw new \InvalidArgumentException(sprintf("User having id '%s' was not found.", $id)); + } + } + catch(\Exception $ex) { + return null; } $this->user->fromArray($user); diff --git a/src/Middleware/PostRequestAuthenticationMiddleware.php b/src/Middleware/PostRequestAuthenticationMiddleware.php index 8912632..e7c3a45 100644 --- a/src/Middleware/PostRequestAuthenticationMiddleware.php +++ b/src/Middleware/PostRequestAuthenticationMiddleware.php @@ -21,7 +21,7 @@ class PostRequestAuthenticationMiddleware implements MiddlewareInterface protected \Closure $loginFailedResponse, PostRequestAuthentication $authenticator = null, ) { - $this->authenticator = $authenticator ?: new PostRequestAuthentication(new Authenticate()); + $this->authenticator = $authenticator ?: new PostRequestAuthentication(new Authenticate($entity)); } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface