cms
cms copied to clipboard
Can't use Nova, Telescope Gate in Laravel
Bug description
i am currently trying to get Laravel Nova and Statamic to work with eloquent and after debugging for 5 hours I found one issue in the statamic AuthServiceProvider:
Gate::before(function ($user, $ability) {
return optional(User::fromUser($user))->isSuper() ? true : null;
});
This before hook also overrides gates defined in Laravel Nova, Telescope, Horizion, ...
Example of Novas default gate:
Gate::define('viewNova', function ($user) {
return in_array($user->email, [
'[email protected]',
]);
});
Can the before be wrapped in something to only be applied to statamics auth?
How to reproduce
If you need a demo repo with Statamic and Telescope for example I could set one up for you if needed.
Logs
No response
Environment
Environment
Application Name: HP
Laravel Version: 10.13.5
PHP Version: 8.1.18
Composer Version: 2.5.5
Environment: staging
Debug Mode: ENABLED
URL: cms.test
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 0
Antlers: runtime
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.7.0 Solo
Installation
Fresh statamic/statamic site via CLI
Antlers Parser
None
Additional details
No response
We use Statamic & Laravel Nova in a couple of apps without any issues.
In our NovaServiceProvider, we do this (we only want super users to access Nova but I imagine you could make roles work here too):
Gate::define('viewNova', function ($user) {
return $user->super;
});
Also, heads up, Telescope will slow your Statamic site down: #5752
This works, but it would be ideal to get the default settings with the emails working too. If we need more fine grained control on Horizon, Telescope, Nova users it doesn't work atm.
I know its an edge case for people using eloquent and auth via eloquent, but honestly I think Statamics Auth/Gate should not interfere with the other services if possible.
In #11516, we made some changes around how Statamic handles authorization (to prevent the issue experienced here). It'll be released as part of Statamic 6.