Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more logs #71

Merged
merged 8 commits into from
Apr 8, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions src/CurrentUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ private function getExpire(): ?int
{
/**
* @var mixed $expire
*
* @psalm-suppress PossiblyNullReference
*/
$expire = $this->authTimeout !== null
Expand All @@ -354,6 +355,7 @@ private function getExpireAbsolute(): ?int
{
/**
* @var mixed $expire
*
* @psalm-suppress PossiblyNullReference
*/
$expire = $this->absoluteAuthTimeout !== null
Expand Down
9 changes: 6 additions & 3 deletions src/Login/LoginMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* `LoginMiddleware` automatically logs user in if {@see IdentityInterface} instance presents in a request
* attribute. It is usually put there by {@see \Yiisoft\Auth\Middleware\Authentication}.
* attribute. It is usually put there by {@see Authentication}.
*/
final class LoginMiddleware implements MiddlewareInterface
{
Expand All @@ -35,7 +35,7 @@ public function __construct(CurrentUser $currentUser, LoggerInterface $logger)
/**
* {@inheritDoc}
*
* Before this middleware, there should be {@see \Yiisoft\Auth\Middleware\Authentication} in the middleware stack.
* Before this middleware, there should be {@see Authentication} in the middleware stack.
* It authenticates the user and places {@see IdentityInterface} instance in the corresponding request attribute.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
Expand All @@ -50,7 +50,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
if ($identity instanceof IdentityInterface) {
$this->currentUser->login($identity);
} else {
$this->logger->warning('Unable to authenticate user by token. Identity not found.');
$this->logger->warning(sprintf(
'Unable to authenticate user by token %s. Identity not found.',
is_scalar($identity) ? ('"' . $identity . '"') : ('of type ' . get_debug_type($identity)),
));
}

return $handler->handle($request);
Expand Down
2 changes: 1 addition & 1 deletion tests/Login/LoginMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testIdentityNotFound(): void
$this->assertNull($this->currentUser
->getIdentity()
->getId());
$this->assertSame('Unable to authenticate user by token. Identity not found.', $this->logger->getLastMessage());
$this->assertSame('Unable to authenticate user by token "null". Identity not found.', $this->logger->getLastMessage());
}

private function createServerRequest(bool $withIdentity = true): ServerRequestInterface
Expand Down