Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Adding route with authentication middleware? #41

Open
tstkenny opened this issue Oct 19, 2015 · 0 comments
Open

Adding route with authentication middleware? #41

tstkenny opened this issue Oct 19, 2015 · 0 comments

Comments

@tstkenny
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant