Auto delete revoked token by expiration date from database
As suggested on the title, I'm using Laravel Passport and trying to figure out how to change some core functions so that when expire date hits a token, it gets removed from the database instead of having its revoked property true!
I don't really see the point in having old tokens in the database, but if there is a reason for that I would be thankful if you could enlighten me.
Hi. You can listen for Laravel\Passport\Events\AccessTokenCreated event and inside your listener, and remove any revoked and/or expired tokens for a user.
Sure thing, you are able to make new artisan command, which will look into tokens table, and remove expired tokens. Using schedule, run that command once a day, or whatever frequency you like.
@AFSHIN.ASGHARI - I think in terms of performance, these two methods are equivalent. Thing is, using an event, you remove all unnecessary user tokens immediately, whenever scheduler will remove all expired tokes for all users, once a day (or whatever frequency you choose).
It is more about what way fits better for your app :)