From ae5a7662cae0a08639628838a066458fa9be9f4a Mon Sep 17 00:00:00 2001 From: Jethro Lin Date: Wed, 4 Dec 2024 12:55:07 +0800 Subject: [PATCH] add command to clean token --- app/Console/Commands/CleanupExpiredTokens.php | 35 +++++++++++++++++++ app/Console/Kernel.php | 28 +++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 app/Console/Commands/CleanupExpiredTokens.php create mode 100644 app/Console/Kernel.php diff --git a/app/Console/Commands/CleanupExpiredTokens.php b/app/Console/Commands/CleanupExpiredTokens.php new file mode 100644 index 0000000..4a12f56 --- /dev/null +++ b/app/Console/Commands/CleanupExpiredTokens.php @@ -0,0 +1,35 @@ +delete(); + + if ($count > 0) { + Log::info("Cleaned up {$count} expired auth tokens"); + $this->info("Successfully cleaned up {$count} expired auth tokens."); + } else { + $this->info('No expired auth tokens found.'); + } + } catch (\Exception $e) { + Log::error('Error cleaning up expired auth tokens', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ]); + $this->error('Failed to clean up expired auth tokens.'); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php new file mode 100644 index 0000000..454280e --- /dev/null +++ b/app/Console/Kernel.php @@ -0,0 +1,28 @@ +command('auth:cleanup-expired-tokens')->daily(); + } + + /** + * Register the commands for the application. + */ + protected function commands(): void + { + $this->load(__DIR__.'/Commands'); + + require base_path('routes/console.php'); + } +}