F
Filament16mo ago
Vp

Multiple panel login

I have three types of user namely 1. admin 2. agent 3. merchant I create multiple panel like /admin, /agent and /merchant I want the users who have user_type = agent only can login in /agent and so on, so 1. Do I need to create multiple custom login page (custom) for each different user_type 2. Can I create one login page (custom) and check base on user_type, if so, how can I know user_type = agent is trying to login using /agent only and block (throw error) if trying to login in /admin and so on Thanks in advance
13 Replies
Dennis Koch
Dennis Koch16mo ago
Do I need to create multiple custom login page (custom) for each different user_type
You need multiple auth guards which you can set on the panel ->authGuard(). Check Laravel docs and your config/auth.php file.
Can I create one login page (custom) and check base on user_type, if so, how can I know user_type = agent is trying to login using /agent only and block (throw error) if trying to login in /admin and so on
You probably can create your own login page, disable all the logins on the panels, and redirect on user type.
Vp
VpOP16mo ago
Okay, understood.. thanks
krekas
krekas16mo ago
For the second you can just add your own loginresponse And make checks there
Dennis Koch
Dennis Koch16mo ago
Yeah right. Good call.
josef
josef16mo ago
Or just adapt canAccessPanel() in the user model and check for panel ID and user_type (that's how I do it)
Dennis Koch
Dennis Koch16mo ago
Instead of auth guards? Yeah might be the easier way.
josef
josef16mo ago
Yep 🙂 guards work too, but might be a bit overkill? Geschmacksfrage I guess 😉
krekas
krekas16mo ago
yeah canAccessPanel() would be easier
SoraKeyheart
SoraKeyheart16mo ago
May you kindly share a code example of this?
krekas
krekas16mo ago
ain't even trying🤦‍♂️
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->hasRole('super_admin');
}

if ($panel->getId() === 'accountant') {
return $this->hasRole('accountant');
}
}
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->hasRole('super_admin');
}

if ($panel->getId() === 'accountant') {
return $this->hasRole('accountant');
}
}
SoraKeyheart
SoraKeyheart16mo ago
I did it like this:
protected $emailList = [
'kaec.net',
'hsse.co'
];

public function getEmailDomain($email){
$array = explode('@', $email);
return $array[1];
}

public function canAccessPanel(Panel $panel): bool
{
// Access to Admin panel
if ($panel->getId() === 'admin' && auth()->user()->hasAnyRole('super_admin', 'admin')) {
return in_array($this->getEmailDomain($this->email),$this->emailList);
}
}
protected $emailList = [
'kaec.net',
'hsse.co'
];

public function getEmailDomain($email){
$array = explode('@', $email);
return $array[1];
}

public function canAccessPanel(Panel $panel): bool
{
// Access to Admin panel
if ($panel->getId() === 'admin' && auth()->user()->hasAnyRole('super_admin', 'admin')) {
return in_array($this->getEmailDomain($this->email),$this->emailList);
}
}
Dennis Koch
Dennis Koch16mo ago
I hope you verify those emailadresses 😅
Want results from more Discord servers?
Add your server