log-viewer: This action is unauthorized

Hi!

if I added to AuthServiceProvider

Gate::define('viewLogViewer', function (User $user) {
            return $user->isAdmin();
        });

LogViewer is load and I can see page, but on left side i got message Request failed with status code 403: This action is unauthorized. No log files were found. It seems like can’t load log files

"message": "This action is unauthorized.",
    "exception": "Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException",

In another project with version 1.8 all working is good

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

For now my issue was solved by removing www from APP_URL.

@arukompas Good to know, thank you. It’s easy to miss it actually. I didn’t find any information about it in the docs. In config file is also not documented. Maybe something could be added like the info found on https://github.com/laravel/sanctum/blob/4.x/config/sanctum.php

@hamza094 hey, it’s usually due to middleware or gate policies being set up incorrectly.

Could you please share:

  • how you’ve defined the Gate for viewing the Log Viewer (or if you haven’t)
  • config/log-viewer.php contents
  • app/Http/Kernel.php contents (in case you have modified the default web middleware group)
  • are you using the default app/Models/User class to represent authenticated user?

Hopefully I’ll be able to help after that 😃

@arukompas I found new problem) If we use in config url like (https://example.com), but in browser open url with www (https://www.example.com/log-viewer) all requests in API will be with error 403

Hi Arunas,

Thanks for your quick reply.

Hereby my answers.

  1. Laravel Framework 9.52.5
  2. Also returns null, unfortunately…
  3. Session ID for the initial load is different than the one from the API, which is strange…! image

On each refresh, the session ID for the initial load remains the same, but the session ID from the API keeps changing on each load.

Any idea what I could be missing?

Thanks for responding. I installed another solution. Usually I would debug this, but right now I don’t have a time for it

Issue was in cookie. If local env without https u have to do this

'secure' => env('SESSION_SECURE_COOKIE', false)

in your config/session.php or in .env file, don’t forget config:cache