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

Adding route with authentication middleware? #41

@tstkenny

Description

@tstkenny

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions