Skip to content

Auth check return false in middleware, but should return true with Log Viewer #428

@zekuraz

Description

@zekuraz

Hi !

I installed Log Viewer in my laravel 11 protect, and works like a charm. But i want to limit who has access to the Log Viewer in production.

So,i create a middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ViewLogs
{
    public function handle(Request $request, Closure $next)
    {
        if (Auth::check() && Auth::user()->hasRole('admin')) {
            return $next($request);
        }
        abort(401, 'Unauthorised');
    }
}

Add the following to $middlewareAliases array In app\Http\Kernel.php

        'view-logs' => \App\Http\Middleware\ViewLogs::class,

And add middleware to the the log viewer config

    /*
    |--------------------------------------------------------------------------
    | Log Viewer route middleware.
    |--------------------------------------------------------------------------
    | Optional middleware to use when loading the initial Log Viewer page.
    |
    */

    'middleware' => [
        'web',
        'view-logs',
        \Opcodes\LogViewer\Http\Middleware\AuthorizeLogViewer::class,
    ],

If i try to debug Auth::check(), it's always return false.

I also try Auth::guard('api'), it's doesn't work.

For information, i use Laravel Passport in my project.

Thanks in advance for your help !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions