Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
use Yiisoft\Auth\IdentityInterface;
use Yiisoft\Auth\IdentityRepositoryInterface;
use Yiisoft\Session\SessionInterface;
use Yiisoft\User\Event\AfterLogout;
use Yiisoft\User\Event\AfterLogin;
use Yiisoft\User\Event\BeforeLogout;
use Yiisoft\User\Event\AfterLogout;
use Yiisoft\User\Event\BeforeLogin;
use Yiisoft\User\Event\BeforeLogout;
use Yiisoft\User\Guest\GuestIdentity;
use Yiisoft\User\Guest\GuestIdentityFactory;
use Yiisoft\User\Guest\GuestIdentityFactoryInterface;
Expand Down Expand Up @@ -307,7 +307,7 @@ private function afterLogout(IdentityInterface $identity): void
private function switchIdentity(IdentityInterface $identity): void
{
$this->identity = $identity;
$this->saveId($identity instanceof GuestIdentityInterface ? null : $identity->getId());
$this->saveId($identity->getId());
}

private function getSavedId(): ?string
Expand Down
6 changes: 1 addition & 5 deletions src/UserAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public function __construct(CurrentUser $currentUser, ResponseFactoryInterface $
$this->responseFactory = $responseFactory;
}

public function authenticate(ServerRequestInterface $request): ?IdentityInterface
public function authenticate(ServerRequestInterface $request): IdentityInterface
{
if ($this->currentUser->isGuest()) {
return null;
}

Comment on lines -31 to -34
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return $this->currentUser->getIdentity();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/UserAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
use PHPUnit\Framework\TestCase;
use Yiisoft\Http\Status;
use Yiisoft\Test\Support\EventDispatcher\SimpleEventDispatcher;
use Yiisoft\User\CurrentUser;
use Yiisoft\User\Guest\GuestIdentityInterface;
use Yiisoft\User\Tests\Support\MockArraySessionStorage;
use Yiisoft\User\Tests\Support\MockIdentity;
use Yiisoft\User\Tests\Support\MockIdentityRepository;
use Yiisoft\User\CurrentUser;
use Yiisoft\User\UserAuth;

final class UserAuthTest extends TestCase
Expand All @@ -33,7 +34,7 @@ public function testIdentityNotAuthenticated(): void
$user = $this->createCurrentUser();
$result = (new UserAuth($user, new ResponseFactory()))->authenticate(new ServerRequest());

$this->assertNull($result);
$this->assertInstanceOf(GuestIdentityInterface::class, $result);
}

public function testChallengeIsCorrect(): void
Expand Down