slimcontroller icon indicating copy to clipboard operation
slimcontroller copied to clipboard

Adding route with authentication middleware?

Open tstkenny opened this issue 9 years ago • 0 comments

I really enjoy using slimcontroller. Is it possible to include an authentication middleware while defining routes in index.php ?

e.g. I have $authenticate defined:

$authenticate = function ($app) { return function () use ($app) { if (!isset($_SESSION['user'])) { $_SESSION['urlRedirect'] = $app->request()->getPathInfo(); $app->flash('error', 'Login required'); $app->redirect('/login'); } }; };

When adding routes:

$app->addRoutes(array( '/' => 'HomeController:login') );

Do something like:

$app->addRoutes(array( '/' => array('HomeController:login', $authenticate)) );

Thank you.

tstkenny avatar Oct 19 '15 02:10 tstkenny