Skip to content

Commit

Permalink
fix: cannot detech other "filament panel" paths pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
cklei-carly committed Aug 12, 2024
1 parent 8baedf2 commit 287347d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
39 changes: 23 additions & 16 deletions src/FilamentAccessManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
namespace SolutionForest\FilamentAccessManagement;

use Closure;
use Filament\Facades\Filament;
use Filament\Navigation\NavigationBuilder;
use Filament\Navigation\NavigationGroup;
use Filament\Navigation\NavigationItem;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Str;
use SolutionForest\FilamentAccessManagement\Http\Auth\Permission;
use SolutionForest\FilamentAccessManagement\Support\Menu;
use SolutionForest\FilamentAccessManagement\Support\Utils;
use Spatie\Permission\PermissionRegistrar;
use Filament\Navigation\NavigationGroup;
use Illuminate\Support\Arr;
use Filament\Navigation\NavigationItem;

class FilamentAccessManagement
{
Expand Down Expand Up @@ -114,18 +114,23 @@ public function createPermissions(): array
*/
public function shouldPassThrough(string|Request $request): bool
{
$excepts = array_unique(
array_merge([
admin_base_path('/'),
admin_base_path('/error*'),
'filament/logout',
'filament/assets*',
], array_map(
fn ($except) => admin_base_path($except),
(array) config('filament-access-management.auth.except', [])
$fiPanel = Filament::getCurrentPanel();

$excepts = array_values(Arr::whereNotNull(array_unique(
array_merge(
[
$fiPanel->getPath(),
(string)str($fiPanel->getPath())->append('/error*'),
$fiPanel->getLoginUrl(),
$fiPanel->getLogoutUrl(),
(string)str($fiPanel->getPath())->append('/assets*'),
],
array_map(
fn ($except) => (string)str($fiPanel->getPath())->append($except),
(array) config('filament-access-management.auth.except', [])
),
)
)
);
)));

$current = is_string($request) ? $request : $request->path();

Expand All @@ -137,7 +142,9 @@ public function shouldPassThrough(string|Request $request): bool
}
}

$current = admin_base_path($current);
$current = (string)str($fiPanel->getPath())
->append('/')
->append(ltrim($current, '/'));

if (Utils::matchRequestPath($except, $current)) {
return true;
Expand Down
5 changes: 3 additions & 2 deletions src/Http/Middleware/Authenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SolutionForest\FilamentAccessManagement\Http\Middleware;

use Filament\Facades\Filament;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use SolutionForest\FilamentAccessManagement\Facades\FilamentAuthenticate;
use SolutionForest\FilamentAccessManagement\Http\Auth\Permission;
Expand All @@ -24,8 +25,8 @@ protected function authenticate($request, array $guards): void
}
}

protected function redirectTo($request): string
protected function redirectTo($request): ?string
{
return route('filament.auth.login');
return Filament::getLoginUrl();
}
}

0 comments on commit 287347d

Please sign in to comment.