Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seems web middleware not called #406

Open
MattiaMarchiorato opened this issue Dec 11, 2024 · 4 comments
Open

seems web middleware not called #406

MattiaMarchiorato opened this issue Dec 11, 2024 · 4 comments

Comments

@MattiaMarchiorato
Copy link

MattiaMarchiorato commented Dec 11, 2024

Hello,

is project upgraded to laravel 11 form 10 recently, we tried to install the package, we add the LogViewer::auth in the AppServiceProvider but when we hit the url http://127.0.0.1:8081/log-viewer seems the $request->user() is empty.

LogViewer::auth(function ($request) {
 return $request->user()->isAdmin();
});
 'middleware' => [
        'web',
        \Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
],
APP_URL=http://127.0.0.1:8081

We also tried with the gate but with the same issue.

With a dd

        LogViewer::auth(function ($request) {
            dd($request->user()->isAdmin());
            return $request->user()->isAdmin();
        });

we receive true

Thanks

@MattiaMarchiorato
Copy link
Author

Adding a custom middleware 'admin'

'middleware' => [
        'web',
        'admin'
 ],

is working, but is very strange that is not working with the LogViewer::auth

@MattiaMarchiorato
Copy link
Author

LogViewer::auth(function ($request) {
            Log::info(['user request', $request->user()]);
            Log::info(['user auth', Auth::user()]);
            return true;
});
Screenshot 2024-12-11 alle 17 12 42

With some logging

@arukompas
Copy link
Contributor

@MattiaMarchiorato hey!

How is your web middleware group defined?

I have created a sample project with default Laravel 11 + Breeze + Log Viewer setup. This could help you see what could be different from your project that might affect authentication.

live demo: https://laravel11-example-auth.log-viewer.opcodes.io/ (user: test@example.com, pass: password)
codebase: https://github.com/opcodesio/laravel-11-log-viewer-example-auth

The demo is hosted on Ubuntu 24.0, using PHP 8.3 and Nginx.

If you can find the differences, or provide your own example repo where we can reproduce the issue, that would be super helpful! Thanks 🙌

@MattiaMarchiorato
Copy link
Author

Hello @arukompas

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Laravel\Jetstream\Http\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

is the classic Laravel 10 middleware group definition.
Right now we are not using this package anymore.

Thanks

MM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants