Correct way to add additional middleware route groups

I have managed to get Jetstream's "EmailVerified" functionality working with Filament by wrapping the resource and pages route groups around it in vendor/filament/filament/routes/web.php :
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
            Route::middleware(config('filament.middleware.auth'))->group(function (): void {
                Route::name('pages.')->group(function (): void {
                    foreach (Filament::getPages() as $page) {
                        Route::group([], $page::getRoutes());
                    }
                });

                Route::name('resources.')->group(function (): void {
                    foreach (Filament::getResources() as $resource) {
                        Route::group([], $resource::getRoutes());
                    }
                });
            });


Obviously this isn't ideal, nor would be publishing the routes file (if that's even possible).
Is there a way I can achieve the same result by adding to the middleware section of the Filament config? Or some other place?
If so, what would be the syntax for this?

If I try and add the middleware route groups in my main web.php, it doesn't respect/know about the Filament ones.
Was this page helpful?