Is It Possible to Use a Single Login URL for All Roles in Filament Shield?

I am currently using Filament Shield with 3 roles: Admin, User, and Courier, and 2 panels: Admin and Courier. The login URLs are currently separated, such as https://url/admin/login for Admin and https://url/courier/login for Courier. I want to change it so that there is only one login URL, like https://url/login. After login, the system will check the user’s role and redirect them to the appropriate panel: If the role is Admin, redirect to the Admin Panel. If the role is Courier, redirect to the Courier Panel. If the role is User, the login should be rejected. Is this possible to achieve with Filament Shield?
23 Replies
Eskie
Eskie2w ago
Povilas K
Povilas K2w ago
Filament Examples
Filament Multiple Panels: Single Login Page for Admin/User Roles
Having multiple panels is excellent for separating users from other roles. However, managing each different login page can be tricky. So, let's make one login page for all panels and switch redirects based on roles.
Nobody
NobodyOP2w ago
Thank you for the information
Nobody
NobodyOP2w ago
I've seen the tutorial you provided when I login using the courier account at url/admin/login still can't login. if I login using the admin account he can login.
No description
Povilas K
Povilas K2w ago
Hard to comment without debugging the full code of your project, sorry
Nobody
NobodyOP2w ago
Based on the tutorial you provided, we only need to create a LoginResponse and register it in the AppServiceProvider, right?
class AppServiceProvider extends ServiceProvider
{
public $singletons = [
\Filament\Http\Responses\Auth\Contracts\LoginResponse::class => \App\Http\Responses\LoginResponse::class,
];
/**
* Register any application services.
*/
public function register(): void
{

}
}
class AppServiceProvider extends ServiceProvider
{
public $singletons = [
\Filament\Http\Responses\Auth\Contracts\LoginResponse::class => \App\Http\Responses\LoginResponse::class,
];
/**
* Register any application services.
*/
public function register(): void
{

}
}
I suspect this Singleton has not been registered properly, why I think so because, when the admin user logs out, he does not receive the Route [login] not defined error message. according to the tutorial
Povilas K
Povilas K2w ago
Yeah maybe in your case something else is required... in our testing that's the only thing we did. Maybe you're on some older Laravel version?
Nobody
NobodyOP2w ago
i am using laravel 11
Povilas K
Povilas K2w ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Povilas K
Povilas K2w ago
What do you mean exactly by "courier can't login"? What error happens after login?
Nobody
NobodyOP2w ago
when I am a courier I try to login with the admin/login url It error like this These credentials do not match our records. but when the courier account tries to login with the courier/login url the courier account can enter the courier panel I have made sure the email and password to login are correct Is this because I am using filament-shield? I use filament shield to ensure that the courier account cannot access the admin panel.
Povilas K
Povilas K2w ago
Mmmm yeah, that may be a good point, in our tutorial we don't use Shield, so maybe that plugin adds extra check for the panel if it doesn't allow you to log in. Sorry, from here I can't help much without debugging your full code and experimenting with it.
Nobody
NobodyOP2w ago
Thank you very much for your reply. I have found the problem.
Povilas K
Povilas K2w ago
Curious what was the problem?
Nobody
NobodyOP2w ago
the problem is in public function canAccessPanel(Panel $panel): bool
CodeWithDennis
Not related to this issue, but wanted to put it here since you guys are talking about it That tutorial was fantastic and really helpful! ✨ Suggestion: It would be great to see another follow-up tutorial that ensures the login page redirects to the correct panel when already logged in. Right now, it just goes to the default panel instead of the one set up in the responses. Feel free to me PM if you need more details 😉 @Povilas K
Povilas K
Povilas K2w ago
@CodeWithDennis great idea, adding on my to-do list!
krekas
krekas2w ago
did you add a simple middleware for that or found a better way?
CodeWithDennis
Haven't fixed it yet 👀
krekas
krekas2w ago
lol I think middlewware is the aproach here. With a simple check and redirect
if (auth()->check() && auth()->user()->is_admin) {
return redirect()->to(Dashboard::getUrl(panel: 'admin'));
}
if (auth()->check() && auth()->user()->is_admin) {
return redirect()->to(Dashboard::getUrl(panel: 'admin'));
}
CodeWithDennis
Probably! I just didn't have time to work on it yet, but thanks for doing my job. 🤣
galli.roberto
galli.roberto4d ago
Set redirect intended on login success to the panel url Or Override response login
krekas
krekas4d ago
reposone login works when user logs in first time not when returns

Did you find this page helpful?