Skip to content

Commit ed96922

Browse files
committed
Refactored isValidAccessToken()
1 parent c7f40af commit ed96922

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/Guard.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ protected function hasValidProvider($tokenable)
113113
*/
114114
protected function isValidAccessToken($accessToken): bool
115115
{
116-
$is_valid = $accessToken && (
117-
($this->expiration && $accessToken->created_at->gt(now()->subMinutes($this->expiration)))
118-
|| $this->hasValidProvider($accessToken->tokenable)
119-
);
116+
if (!$accessToken) {
117+
return false;
118+
}
119+
120+
$is_valid =
121+
(!$this->expiration || $accessToken->created_at->gt(now()->subMinutes($this->expiration)))
122+
&& $this->hasValidProvider($accessToken->tokenable);
120123

121124
if (is_callable(Sanctum::$validateCallback)) {
122125
$is_valid = (bool) (Sanctum::$validateCallback)($accessToken, $is_valid);

src/Sanctum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Sanctum
2828
*
2929
* @var callable|null
3030
*/
31-
public static $validateCallback = null;
31+
public static $validateCallback;
3232

3333
/**
3434
* Set the current user for the application with the given abilities.

0 commit comments

Comments
 (0)