diff --git a/src/AAuthServiceProvider.php b/src/AAuthServiceProvider.php index 5b24842..14b2b85 100644 --- a/src/AAuthServiceProvider.php +++ b/src/AAuthServiceProvider.php @@ -53,8 +53,22 @@ public function boot(): void ); }); + // Register AAuth permissions with Laravel's Gate system + // This allows AAuth permissions to work alongside Laravel's native gates and policies Gate::before(function ($user, $ability, $arguments = []) { - return app('aauth')->can($ability) ?: null; + // Only return true if AAuth explicitly grants this permission + // Return null to allow Laravel's gate/policy checks to continue + try { + if (app('aauth')->can($ability)) { + return true; + } + } catch (\Throwable $e) { + // If AAuth service is not properly initialized, let Laravel's gates handle it + return null; + } + + // Return null instead of false to allow Laravel's gates and policies to be checked + return null; }); Blade::directive('aauth', function ($permission) { diff --git a/src/Traits/AAuthUser.php b/src/Traits/AAuthUser.php index 5d0fda7..97d7a18 100644 --- a/src/Traits/AAuthUser.php +++ b/src/Traits/AAuthUser.php @@ -75,12 +75,23 @@ public function getDeletableAttribute(): bool public function can($abilities, $arguments = []): bool { if (is_string($abilities)) { - return app('aauth')->can($abilities); + // First check if AAuth has this permission + try { + if (app('aauth')->can($abilities)) { + return true; + } + } catch (\Throwable $e) { + // If AAuth is not properly initialized, fall through to Laravel's Gate + } + + // If AAuth doesn't have this permission, delegate to Laravel's Gate system + // This allows Laravel's native gates and policies to be checked + return parent::can($abilities, $arguments); } if (is_array($abilities)) { foreach ($abilities as $ability) { - if (! app('aauth')->can($ability)) { + if (! $this->can($ability, $arguments)) { return false; } }