Restrict user access to different panels based on roles

I have 2 pannels One is Pharmacy and other is clinic. I have one login page , based on roles I am redirecting to the panels.
Solution:
OK, yeah, so I was missing
->authMiddleware([
Authenticate::class,
])
->authMiddleware([
Authenticate::class,
])
...
Jump to solution
9 Replies
Dennis Koch
Dennis Koch13mo ago
And what's the question?!
sdousley
sdousley3d ago
Sorry to jump on a slightly older post - but I've done this, and implemented the canAcecssPanel method. However, even if it returns false, it still allows the user to see the panel
Dennis Koch
Dennis Koch3d ago
Is the method called at all?
sdousley
sdousley3d ago
it is, if I dd() something in there, I see that happen
Dennis Koch
Dennis Koch3d ago
What happens if you switch env to production? Not 100% sure whether it’s enforced in local but I think it should be
sdousley
sdousley3d ago
Ah yeah, I did notice that, and change that (not that I cach anything locally in dev, but cleared cache anyway) and still just lets me view the panel I even just have it return false, and it still works
public function canAccessPanel(Panel $panel): bool
{
return false;
}
public function canAccessPanel(Panel $panel): bool
{
return false;
}
if i
dd(App::environment());
dd(App::environment());
within that, I get "production" back ok, so I just went back to my default, and the return false gave me a 403 changed false to true, and it worked so is there something I need to put on each panel for that to work
Solution
sdousley
sdousley3d ago
OK, yeah, so I was missing
->authMiddleware([
Authenticate::class,
])
->authMiddleware([
Authenticate::class,
])
sdousley
sdousley3d ago
from my non-default panel

Did you find this page helpful?