Created
May 21, 2024 14:06
-
-
Save POMXARK/e916c25b5a7a8e9d1fc070b5f639b6c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Filament\Facades\Filament; | |
use Filament\Models\Contracts\FilamentUser; | |
use Illuminate\Auth\Middleware\Authenticate as Middleware; | |
use Illuminate\Support\Facades\Session; | |
class RedirectIfNotFilamentAdmin extends Middleware | |
{ | |
protected function authenticate($request, array $guards): void | |
{ | |
$auth = Filament::auth(); | |
$user = $auth->user(); | |
$panel = Filament::getCurrentPanel(); | |
if (!($auth->check() | |
&& $user instanceof FilamentUser | |
&& $user->canAccessPanel($panel))) { | |
Session::flush(); | |
$this->unauthenticated($request, $guards); | |
} | |
} | |
protected function redirectTo($request): ?string | |
{ | |
return Filament::getLoginUrl(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment