F
Filament16mo ago
lodeki

Redirect Middleware for multiple panels.

I want to redirect user to their respective panel based on their role using this middleware
if (Auth::check()) {
if (Auth::user()->hasRole('Manager')) {
return redirect()->route('filament.manager.pages.dashboard');
} else if (Auth::user()->hasRole('Super Admin')) {
return redirect()->route('filament.admin.pages.dashboard');
}
}
return $next($request);
if (Auth::check()) {
if (Auth::user()->hasRole('Manager')) {
return redirect()->route('filament.manager.pages.dashboard');
} else if (Auth::user()->hasRole('Super Admin')) {
return redirect()->route('filament.admin.pages.dashboard');
}
}
return $next($request);
. I added the middleware in the Admin panel whose path('').I also have the manager panel whose path('manager') that i didn't add the middleware nor added the ->login(). However i keep on getting This page is not working when i try to log in. Sometimes I get Route [login] not defined. I've made an intensive such on the platform and tried every suggestion including creating a custom redirect in web.php but to no avail.
8 Replies
lodeki
lodekiOP16mo ago
I still get the error on 'manager' logout Route [login] not defined Got it ,added the ->login() on the manager panel. Thank you . Though when logged in as admin then i hit the '/manager' , it takes me to the manager panel but with the same admin squint
krekas
krekas16mo ago
you need to restrict access in the canAccessFilament() method
lodeki
lodekiOP16mo ago
Not really sure how to go about . I do check the role of the user , if 'manager' ? If 'super admin' ?
krekas
krekas16mo ago
check panel id and users roles
lodeki
lodekiOP16mo ago
if('manager'){//what should be here}else if('super admin') {//and here} . sorry for the dumb question but i seem not wrap it up.Suppose the currently logged in is a manager [ viewing MangerPanel] ,should canAccessPanel() return true or false so that he doesn't see the admin panel
krekas
krekas16mo ago
$panel->getId() or something similar. Don't remember exactly. Use ide to find
Want results from more Discord servers?
Add your server