-
I'm attempting to nest some routes for Shield in a path called "secure" and having some routing issues. Any help would be appreciated. The intention is to have the following:
I implemented the following in my Config/Routes.php I then set up a group for the routes: $routes->group('secure', static function ($routes) {
// public routes
$routes->get('logout', 'Secure\AuthController::logoutAction');
$routes->get('login', 'Secure\AuthController::loginView');
$routes->post('login', 'Secure\AuthController::loginAction');
//protected routes
$routes->group('account', ['filter' => 'session'], function ($routes) {
$routes->get('/', 'Secure\AccountController::index');
$routes->get('/example', 'Secure\AccountController::exampleMethod');
});
}); The login process works fine, everything is excellent. The issue is if I log out and then attempt to view domain.com/secure/account, it throws a reverse routing error. When I move the login page outside of the nested path and put it back on the top level, domain.com/login, and then access domain.com/secure/account, it routes me to domain.com/login as expected. It appears that the session filter doesn't know to look within the grouped routes for the updated location of the login route? Is there a location to set this? And to complicate a little more, in some cases, I will want the user to go back to the login page, but in other cases, I will want to display a 404. Do I need to write my own filter to handle which routes are protected and how to conditionally divert the redirect afterward? Thanks for any guidance. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Can you share your app/Config/Routes.php and AuthRoutes.php? Also is that the exact exception message? It looks like the route name got clipped from the error, or maybe something else is going on. |
Beta Was this translation helpful? Give feedback.
-
You need to define named route See shield/src/Filters/SessionAuth.php Line 53 in 93f607f |
Beta Was this translation helpful? Give feedback.
You need to define named route
login
.https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#using-named-routes
See
shield/src/Filters/SessionAuth.php
Line 53 in 93f607f