Skip to content

Commit

Permalink
fix: dont revoke tokens when a new one is created
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Jun 30, 2023
1 parent a106802 commit fcb5de6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 1 addition & 9 deletions app/Services/UserTokenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class UserTokenService
{
/**
* Creates an access token for the given user and revokes
* any existing.
* Creates an access token for the given user.
*
* @param integer $userCid
* @throws ModelNotFoundException
Expand All @@ -21,13 +20,6 @@ public function create(int $userCid) : string
{
$user = User::findOrFail($userCid);

// Revoke existing tokens
if ($user->tokens) {
foreach ($user->tokens as $token) {
$token->revoke();
}
}

return $user->createToken('access', [AuthServiceProvider::SCOPE_USER])->accessToken;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/app/Services/UserTokenServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function testItThrowsAnExceptionIfUserNotFound()
$this->service->create(999);
}

public function testItOnlyAllowsOneActiveToken()
public function testItOnlyAllowsMultipleActiveTokens()
{
$this->service->create(1203533);
$this->service->create(1203533);
$this->service->create(1203533);
$this->service->create(1203533);

$this->assertEquals(1, Token::where('user_id', 1203533)->where('revoked', false)->get()->count());
$this->assertEquals(4, Token::where('user_id', 1203533)->where('revoked', false)->get()->count());
}

public function testItCreatesAUserToken()
Expand Down

0 comments on commit fcb5de6

Please sign in to comment.