JWTRefreshTokenBundle icon indicating copy to clipboard operation
JWTRefreshTokenBundle copied to clipboard

Question: Getting rows affected by token deletion

Open rajivraman-MRM opened this issue 6 months ago • 6 comments

It would be helpful if delete() returned the number of rows affected. I need this to ensure that a single-use token is truly only refreshed once.

Instead, I am using DQL to get this information:

$q = $this->entityManager->createQuery('delete from Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken rt where rt.id = :id');
$q->setParameter('id', $refreshToken->getId());
$numDeleted = $q->execute();

But it would be nice if $this->refreshTokenManager->delete($refreshToken) returned this info for me.

rajivraman-MRM avatar Jul 17 '25 19:07 rajivraman-MRM

@rajivraman-MRM do you want to sent a new PR for this? Thanks

shakaran avatar Jul 17 '25 19:07 shakaran

@rajivraman-MRM do you want to sent a new PR for this? Thanks

@shakaran I'm currently just doing this in a controller, but sure I can work on a PR.

rajivraman-MRM avatar Jul 17 '25 19:07 rajivraman-MRM

@rajivraman-MRM I just made the PR https://github.com/markitosgv/JWTRefreshTokenBundle/pull/405

Let me know if works fine for you in master

shakaran avatar Jul 17 '25 22:07 shakaran

@rajivraman-MRM I just made the PR #405

Let me know if works fine for you in master

@shakaran thank you for jumping on it! Unfortunately, that patch is still prone to race condition. Two threads can both findOneBy the record, and attempt the delete. But only one will succeed. Seems the only way to truly get the number of rows affected from the delete is by calling execute.

rajivraman-MRM avatar Jul 18 '25 13:07 rajivraman-MRM

@rajivraman-MRM I just made the PR #405

Let me know if works fine for you in master

@shakaran thank you for jumping on it! Unfortunately, that patch is still prone to race condition. Two threads can both findOneBy the record, and attempt the delete. But only one will succeed. Seems the only way to truly get the number of rows affected from the delete is by calling execute.

ok, waiting for you pull request covering the case. Take in mind the ObjectManager with remove doesnt return info and we dont have the createQuery

shakaran avatar Jul 18 '25 14:07 shakaran

@shakaran I opened https://github.com/markitosgv/JWTRefreshTokenBundle/pull/406

rajivraman-MRM avatar Jul 18 '25 19:07 rajivraman-MRM