From 71310844d49cf26cb336f4bac7c16e6dd1ce58e8 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 7 Jan 2025 09:13:39 +0800 Subject: [PATCH] [7.x] Prevent authentication route registrations when `auth: false` (#289) * [7.x] Prevent authentication route registrations when `auth: false` Signed-off-by: Mior Muhammad Zaki * wip Signed-off-by: Mior Muhammad Zaki --------- Signed-off-by: Mior Muhammad Zaki --- src/Concerns/InteractsWithWorkbench.php | 2 +- src/Workbench/Workbench.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Concerns/InteractsWithWorkbench.php b/src/Concerns/InteractsWithWorkbench.php index 90ef8026..679ec794 100644 --- a/src/Concerns/InteractsWithWorkbench.php +++ b/src/Concerns/InteractsWithWorkbench.php @@ -73,7 +73,7 @@ protected function getPackageProvidersUsingWorkbench($app): ?array $hasAuthentication = $config?->getWorkbenchAttributes()['auth'] ?? false; $providers = $config?->getExtraAttributes()['providers'] ?? []; - if ($hasAuthentication && class_exists('Orchestra\Workbench\AuthServiceProvider')) { + if ($hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider')) { $providers[] = 'Orchestra\Workbench\AuthServiceProvider'; } diff --git a/src/Workbench/Workbench.php b/src/Workbench/Workbench.php index eb3cba17..fbbdf3bc 100644 --- a/src/Workbench/Workbench.php +++ b/src/Workbench/Workbench.php @@ -86,10 +86,12 @@ public static function start(ApplicationContract $app, ConfigContract $config, a */ public static function startWithProviders(ApplicationContract $app, ConfigContract $config): void { - static::start($app, $config, [ - 'Orchestra\Workbench\AuthServiceProvider', + $hasAuthentication = $config->getWorkbenchAttributes()['auth'] ?? false; + + static::start($app, $config, array_filter([ + $hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider') ? 'Orchestra\Workbench\AuthServiceProvider' : null, 'Orchestra\Workbench\WorkbenchServiceProvider', - ]); + ])); } /**