Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/AAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 13 additions & 2 deletions src/Traits/AAuthUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down