F
Filament7mo ago
Wim

Seperate panels per role with no cross-access

I have two panels: admin panel and user panel. I use the Spatie Roles and Permissions plugin. I have two roles (user and admin). I want to ensure that users cannot access the admin panel and admins cannot access the user panel. I have the following solution: I created an AdminPanelProvider and a UserPanelProvider. I'm customizing both to my liking. In order to ensure both roles can only access their respective panel, I created two middlewares: CheckRoleAdminMiddleware and CheckRoleUserMiddleware. CheckRoleAdminMiddleware: $user = Auth::user(); if (auth()->check()) { if ($user->hasRole('user')) { Auth::logout(); return Redirect::to('/admin/login'); } } return $next($request); and CheckRoleUserMiddleware: $user = Auth::user(); if (auth()->check()) { if ($user->hasRole('admin')) { Auth::logout(); return Redirect::to('/user/login'); } } return $next($request); This seems to be working but I was wondering if this is the best (or the most elegant) way to achieve this. If you have better ideas, feel free to share them (y)
1 Reply
Wim
Wim7mo ago
@Dennis Koch Hi Dennis, you mind having a quick look at above. It works but maybe there's better ways to achieve the same. I feel like this functionality would be a good candidate to build in into Filament. If not done already?