Answer the question
In order to leave comments, you need to log in
How to hang authorization on all routes?
Greetings!
Then my application grew, moved to Slim, and here's the question:
now I insert a controller into each route that checks access rights to this section + authorization.
for example:
/cabinet
/cabinet/1
/cabinet/2
/cabinet/2/2
/cabinet/2/3/info
And everything would be fine, but if there are 100 such pages, there will be a lot of extra code.
Is it possible to somehow determine once that the controller worked for each route. I so understand it is necessary to look in the direction of Route Group and Middleware?
Answer the question
In order to leave comments, you need to log in
yes, you need to use middleware, grouping routes as needed
Video course Authentication with Slim 3
Look, the cabinet controller must inherit the base controller, get the desired route in the base controller and check something like. Or rather, see the documentation of your framework) Or wait for the answer of someone who understood SLIM
if(Auth::check() == false && $route['controller'] != 'Login'){
redirect('/admin/login/'); die;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question