Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AGN907's avatar
Level 1

Auth middleware runs before custom middleware

I have a custom middleware that checks if the app setup has been done and redirects to the setup route.

This middleware is the first middleware that is supposed to run on the dashboard route, if the setup is done it will move to the auth middleware to check if the user is authenticated otherwise redirects to login.

My problem is if I only include the setup middleware it works flawlessly but if I add the auth middleware after it, the auth middleware is the only one that runs.

Route::get('dashboard', [AdminDashboardController::class, 'index'])->middleware(['setup-done', 'auth'])->name('dashboard.index');

I fixed the problem by specifying the priority of the setup middleware.

withMiddleware(function (Middleware $middleware) {
        $middleware->priority([
            EnsureSetupDone::class,
        ]);
    })

What I want to ask is, don't the docs say that the route middleware runs in the order it's specified? Or does the built-in auth middleware have a higher priority over all custom middleware?

0 likes
0 replies

Please or to participate in this conversation.