F
Filament3mo ago
Myster

Allow only users with specific roles to access the login.

Hi, I'm in a filament project with FilamentShield plugin. I have two panels, one for admin and one for a regular user. The admin has the super_admin role and the user has the user role. It is worth mentioning that the project has other roles. How do I so that, on the /admin route, only the super_admin can log in and that too on the /user route. How can I prevent other users with different roles from logging in? Plugin: FilamentShield.
3 Replies
Matthew
Matthew3mo ago
Not sure about the plugin, but for multiple panels, you just set up different auth guards: https://filamentphp.com/docs/3.x/panels/users#setting-the-authentication-guard
Mehdi
Mehdi3mo ago
Try this: namespace App\Models; use Filament\Models\Contracts\FilamentUser; use Filament\Panel; use BezhanSalleh\FilamentShield\Support\Utils; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable implements FilamentUser { //..
public function canAccessPanel(Panel $panel): bool { if($panel->getId() === 'admin') { return $this->hasRole(Utils::getSuperAdminName()); } elseif($panel->getId() === 'app') { return $this->hasRole(Utils::getSuperAdminName()) || $this->hasRole(config('filament-shield.user.name', 'user')); } return false; } }
Myster
MysterOP3mo ago
Thx
Want results from more Discord servers?
Add your server