diff --git a/src/Lib/Authenticate.php b/src/Lib/Authenticate.php index 29f5977..e876d31 100644 --- a/src/Lib/Authenticate.php +++ b/src/Lib/Authenticate.php @@ -37,6 +37,8 @@ class Authenticate { { $logUser = function(int $id) use ($repository) { if ( null === ( $user = $repository->loadFromPk($id) ) ) { + $this->logout(); + throw new \Exception("User not found."); } @@ -61,7 +63,7 @@ class Authenticate { $this->session->destroy(); } - public function authenticate(\Ulmus\Repository $repository, array $userLogin, string $password) : User + public function authenticate(\Ulmus\Repository $repository, array $userLogin, ? string $password) : User { foreach($userLogin as $field => $value) { $repository->or($field, $value); @@ -111,7 +113,7 @@ class Authenticate { $this->cookie->delete('user.id'); } - $this->user->logged = false; + $this->user && $this->user->logged = false; return $this; }