diff --git a/config/websockets.php b/config/websockets.php index 40aaa24eeb..fbb9e230d9 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -1,5 +1,7 @@ 'laravel-websockets', + /* + * Dashboard Routes Middleware + * + * These middleware will be assigned to every dashboard route, giving you + * the chance to add your own middleware to this list or change any of + * the existing middleware. Or, you can simply stick with this list. + */ + 'middleware' => [ + 'web', + Authorize::class, + ], + 'statistics' => [ /* * This model will be used to store the statistics of the WebSocketsServer. diff --git a/src/Dashboard/Http/Middleware/Authorize.php b/src/Dashboard/Http/Middleware/Authorize.php index 772107fc78..1883c35eef 100644 --- a/src/Dashboard/Http/Middleware/Authorize.php +++ b/src/Dashboard/Http/Middleware/Authorize.php @@ -8,6 +8,6 @@ class Authorize { public function handle($request, $next) { - return Gate::check('viewWebSocketsDashboard') ? $next($request) : abort(403); + return Gate::check('viewWebSocketsDashboard', [$request->user()]) ? $next($request) : abort(403); } } diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index 3c821260a4..d049605fa8 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -62,7 +62,7 @@ public function register() protected function registerRoutes() { Route::prefix(config('websockets.path'))->group(function () { - Route::middleware(AuthorizeDashboard::class)->group(function () { + Route::middleware(config('websockets.middleware', [AuthorizeDashboard::class]))->group(function () { Route::get('/', ShowDashboard::class); Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); Route::post('auth', AuthenticateDashboard::class); @@ -79,7 +79,7 @@ protected function registerRoutes() protected function registerDashboardGate() { - Gate::define('viewWebSocketsDashboard', function ($user = null) { + Gate::define('viewWebSocketsDashboard', function ($user) { return app()->environment('local'); });