Filament 3, connect two tables admins or users for login
I'm using filament 3, I want to connect two tables admins or users for login view. I don't have no roles. just two tables that has email and password.
For example:
admins table:
[email protected]/Test@123
users table:
[email protected]/Test@123
I can able to login both tables credentials in the filament back office
Can you please suggest?
6 Replies
just customize the login page:
in this sample I login with both email or phone just with overriding
For your case just override the
authenticate
method in the Login
class
to use the new custom login page class, in the panel provider just add the class to the loggin method
As above, but you would override teh authetnicate method, first try authenticating against the user table, else authetnication against the admin table. else return fail.
Thanks for suggestion
Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)
Is possible to add guard in the above code?
Like
Filament::guard('user')->auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false);
Filament::guard('admin')->auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)
Thanks for suggestion, I have two guards admin or users
Filament::auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)
Is possible to add guard in the above code?
Like
Filament::guard('user')->auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false);
Filament::guard('admin')->auth()->attempt($this->getCredentialsFromFormData($data), $data['remember'] ?? false)
Not that I know off no, it's defined on the panel
Just authetnmicate manually you don't need to use filamentment to handle the auth
Do you have a panel for Admin and users? If so, the panel you access under will determine the auth guard.
If you are manually doing it with a custom login page and redirect to desired panel, then just auth as normal laravel
ok
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel) : Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->authGuard('admin')
->login(CustomLogin::class)
->colors([
'primary' => Color::Amber,
])
-------------
}
}
is possible to add two panel in the PanelProvider?
No
The Login class will determine the guard in use natively