Authorizing access to Log Viewer with token

109 Views Asked by At

I'm trying to Authorize access to Log Viewer, I'm using laravel to build API and JWT to generate token and spatie Package for Roles and Permissions.

I created this middleware:

    {
        if (Auth::check() && Auth::user()->hasPermissionTo('view-logs')) {
            return $next($request);
        }

        abort(401, 'Unauthorised');
    }

and publish log-viewer-views by this command: php artisan vendor:publish --tag=log-viewer-views

in the blade file:

<!-- Global LogViewer Object -->
<script>
    window.LogViewer = @json($logViewerScriptVariables);

    // Add additional headers for LogViewer requests like so:
    var token = localStorage.getItem('Authorization');
    window.LogViewer.headers['Authorization'] ='Bearer ' + token;

</script>

but the middleware can't see the user is Auth it's always return 401 UNAUTHORIZED

I thing the blade didn't send the token

Set the token manually in local storage and Debug each step

0

There are 0 best solutions below