Skip to content

Commit

Permalink
Update getCredential to only refresh creds once per request
Browse files Browse the repository at this point in the history
Signed-off-by: Russ <[email protected]>
  • Loading branch information
ComputerTinker authored Apr 5, 2024
1 parent 908ff13 commit 40a009c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Guards/AuthenticationGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ final class AuthenticationGuard extends GuardAbstract implements AuthenticationG
*/
protected const TELESCOPE = '\Laravel\Telescope\Telescope';

/**
* @var bool
*/
private bool $didCredRefresh = false;

public function find(): ?CredentialEntityContract
{
if ($this->isImpersonating()) {
Expand Down Expand Up @@ -92,10 +97,15 @@ public function getCredential(): ?CredentialEntityContract
return $this->getImposter();
}

if (!empty($this->didCredRefresh)) {

Check failure on line 100 in src/Guards/AuthenticationGuard.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2)

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 100 in src/Guards/AuthenticationGuard.php

View workflow job for this annotation

GitHub Actions / Psalm (8.2)

InvalidArgument

src/Guards/AuthenticationGuard.php:100:20: InvalidArgument: Calling empty on a boolean value is almost certainly unintended (see https://psalm.dev/004)

Check failure on line 100 in src/Guards/AuthenticationGuard.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3)

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 100 in src/Guards/AuthenticationGuard.php

View workflow job for this annotation

GitHub Actions / Psalm (8.3)

InvalidArgument

src/Guards/AuthenticationGuard.php:100:20: InvalidArgument: Calling empty on a boolean value is almost certainly unintended (see https://psalm.dev/004)
return $this->credential;
}

if ($this->credential instanceof CredentialEntityContract) {
$updated = $this->findSession();
$this->setCredential($updated);
$this->pushState($updated);
$this->didCredRefresh = true;
}

return $this->credential;
Expand Down

0 comments on commit 40a009c

Please sign in to comment.