0

So basically I work on a Laravel 11 project, and the session cookie is generated by a portal from which I access my application.

I have an AuthMiddleware aliased to 'sso' which is responsible for requesting to the portal app with the cookie and retrieve the user, and authenticate him.

I'm using a library in my vendors which exposes routes which are protected by a middleware aliased to 'api'.

My issue is that since I don't have any middleware aliased to 'api' in my application, my user is never authenticated and thus, I can't use the library for the moment.

I tried to replace my alias 'sso' to api like so :

->withRouting(
    web: __DIR__ . '/../routes/web.php',
    api: __DIR__ . '/../routes/api.php',
    commands: __DIR__ . '/../routes/console.php',
    health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'api' => AuthMiddleware::class,
    ]);

but if I try to dd() something from within AuthMiddleware, this middleware is never called when associated to alias 'api'.

What's wrong ? is there a mismatch somewhere ?

Thanks.

1 Answer 1

0

I finally found the solution :

->withRouting(
    web: __DIR__ . '/../routes/web.php',
    api: __DIR__ . '/../routes/api.php',
    commands: __DIR__ . '/../routes/console.php',
    health: '/up',
    then: function () {
        Route::middleware('sso')
            ->group(base_path('vendor/path/to/routes/api.php'));
    }
)

My 'sso' middleware is not overriding the 'api' middleware mentionned in the dependency route file.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.