Skip to content

Commit b40c589

Browse files
authored
Merge pull request #376 from kenjis/fix-AccessTokens-no-data-to-update
fix: AccessTokens throws DataException
2 parents 7d4cb34 + 09b7ec5 commit b40c589

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Authentication/Authenticators/AccessTokens.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ public function check(array $credentials): Result
125125
}
126126

127127
$token->last_used_at = Time::now()->format('Y-m-d H:i:s');
128-
$identityModel->save($token);
128+
129+
if ($token->hasChanged()) {
130+
$identityModel->save($token);
131+
}
129132

130133
// Ensure the token is set as the current token
131134
$user = $token->user();

tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public function testCheckSuccess(): void
155155

156156
$updatedToken = $result->extraInfo()->currentAccessToken();
157157
$this->assertNotEmpty($updatedToken->last_used_at);
158+
159+
// Checking token in the same second does not throw "DataException : There is no data to update."
160+
$this->auth->check(['token' => $token->raw_token]);
158161
}
159162

160163
public function testAttemptCannotFindUser(): void

0 commit comments

Comments
 (0)