Skip to content

Commit 6505902

Browse files
committed
fix: add User null check
1 parent 3adb586 commit 6505902

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Authentication/Authenticators/Session.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use CodeIgniter\Shield\Authentication\AuthenticatorInterface;
1111
use CodeIgniter\Shield\Authentication\Passwords;
1212
use CodeIgniter\Shield\Entities\User;
13+
use CodeIgniter\Shield\Exceptions\LogicException;
1314
use CodeIgniter\Shield\Models\LoginModel;
1415
use CodeIgniter\Shield\Models\RememberModel;
1516
use CodeIgniter\Shield\Models\UserIdentityModel;
@@ -113,9 +114,11 @@ public function attempt(array $credentials): Result
113114
*/
114115
public function checkAction(string $type, string $token): bool
115116
{
116-
$user = $this->loggedIn()
117-
? $this->getUser()
118-
: null;
117+
$user = $this->loggedIn() ? $this->getUser() : null;
118+
119+
if ($user === null) {
120+
throw new LogicException('Cannot get the User.');
121+
}
119122

120123
$identity = $user->getIdentity($type);
121124

0 commit comments

Comments
 (0)