outl1ne / nova-settings

A Laravel Nova tool for editing custom settings using native Nova fields.
MIT License
274 stars 97 forks source link

Authorization not working with gate #136

Closed olivervo closed 2 years ago

olivervo commented 2 years ago

I'm having an issue authorizing the package using the canSee method and a gate.

NovaServiceProvider.php

NovaSettings::make()->canSee(
                function ($request) {
                    return $request->user()->can('permissions.admin');
                }
            ),

The tool is visible in the side menu which would imply that the authorization is working. However once clicked on it gives a 500 error and Call to a member function can() on null is logged meaning $request->user() is returning null.

It seems like something is happening behind the scenes on click which doesn't pass canSee the correct $request? Using the Auth::user() results in the same error. Testing with other packages don't result in the same error.

Tarpsvo commented 2 years ago

That's weird. It works for me, I did a simple test:

\Outl1ne\NovaSettings\NovaSettings::make()->canSee(function ($request) {
  return $request->user()->id === 1;
}),

Maybe it was fixed in a Nova update?