Skip to content

Commit b8bb2c0

Browse files
committed
fix: depend on Authenticatable, not User
1 parent 072c078 commit b8bb2c0

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function getBearerToken(): ?string
227227
*/
228228
public function recordActive(): void
229229
{
230-
if (! $this->user instanceof User) {
230+
if (! $this->user instanceof Authenticatable) {
231231
throw new InvalidArgumentException(self::class . '::recordActive() requires logged in user before calling.');
232232
}
233233

src/Authentication/Authenticators/Session.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,7 @@ public function loggedIn(): bool
172172
*/
173173
public function login(Authenticatable $user): bool
174174
{
175-
/**
176-
* @todo Authenticatable should define getEmailIdentity() or this should require User
177-
*/
178-
if (! $user instanceof User) {
179-
throw new InvalidArgumentException(self::class . '::login() only accepts Shield User');
180-
}
181-
175+
// @todo Authenticatable should define getEmailIdentity() or this should require User
182176
$this->user = $user;
183177

184178
// Update the user's last used date on their password identity.
@@ -297,7 +291,7 @@ public function getUser(): ?Authenticatable
297291
*/
298292
public function recordActive(): void
299293
{
300-
if (! $this->user instanceof User) {
294+
if (! $this->user instanceof Authenticatable) {
301295
throw new InvalidArgumentException(self::class . '::recordActive() requires logged in user before calling.');
302296
}
303297

src/Controllers/RegisterController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodeIgniter\Events\Events;
77
use CodeIgniter\HTTP\RedirectResponse;
88
use CodeIgniter\Shield\Entities\User;
9+
use CodeIgniter\Shield\Interfaces\Authenticatable;
910
use CodeIgniter\Shield\Interfaces\UserProvider;
1011
use CodeIgniter\Validation\Validation;
1112

@@ -115,7 +116,7 @@ protected function getUserProvider(): UserProvider
115116
/**
116117
* Returns the Entity class that should be used
117118
*/
118-
protected function getUserEntity(): User
119+
protected function getUserEntity(): Authenticatable
119120
{
120121
return new User();
121122
}

src/Models/UserModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use CodeIgniter\Model;
66
use CodeIgniter\Shield\Authentication\Traits\UserProvider as UserProviderTrait;
77
use CodeIgniter\Shield\Entities\User;
8+
use CodeIgniter\Shield\Interfaces\Authenticatable;
89
use CodeIgniter\Shield\Interfaces\UserProvider;
910
use Faker\Generator;
1011
use InvalidArgumentException;
@@ -101,7 +102,7 @@ protected function fetchIdentities(array $data): array
101102
* Adds a user to the default group.
102103
* Used during registration.
103104
*/
104-
public function addToDefaultGroup(User $user): void
105+
public function addToDefaultGroup(Authenticatable $user): void
105106
{
106107
$defaultGroup = setting('AuthGroups.defaultGroup');
107108
$allowedGroups = array_keys(setting('AuthGroups.groups'));

src/Test/AuthenticationTesting.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodeIgniter\Shield\Test;
44

55
use CodeIgniter\Shield\Entities\User;
6+
use CodeIgniter\Shield\Interfaces\Authenticatable;
67

78
/**
89
* Trait AuthenticationTesting
@@ -16,7 +17,7 @@ trait AuthenticationTesting
1617
*
1718
* @return $this
1819
*/
19-
public function actingAs(User $user)
20+
public function actingAs(Authenticatable $user)
2021
{
2122
// Ensure the helper is loaded during tests.
2223
helper('auth');

0 commit comments

Comments
 (0)