Skip to content

Bug: auth.required middleware is not triggered on dynamic routes within app()->group() #32

@ronaldomussa

Description

@ronaldomussa

When using auth.required middleware inside app()->group(), dynamic routes like /clients/{id} skip the middleware execution. This causes the controller to be executed even if there’s no authenticated user.

It works fine on static routes like /clients, but on dynamic ones, the middleware is ignored.

Steps to reproduce the behavior:

In your routes/web.php, define a middleware group:

app()->group('/cms', [
    'middleware' => 'auth.required',
    function () {
        app()->get('/clients', 'Auth\ClientController@index');
        app()->get('/clients/{id}', 'Auth\ClientController@show');
    }
]);

Ensure your auth.required middleware redirects if the user is not logged in.

Access /cms/clients while logged out → ✅ Middleware works (redirects).

Access /cms/clients/1 while logged out → ❌ Controller runs, middleware is skipped.

Expected behavior
All routes (static or dynamic) inside the app()->group() with auth.required should be protected. If a user is not logged in, the middleware should redirect and prevent controller execution.

Additional context
Leaf version: v3.x

Middleware is registered via auth()->middleware('auth.required', callback)

DevTools log shows controller is called before the middleware on dynamic routes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions