From bd0bf21a0b79cced71fa35f727b21eacf1bde7ef Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 9 Oct 2023 09:34:13 +0900 Subject: [PATCH 1/2] docs: add about locale routes --- docs/customization/route_config.md | 39 +++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/customization/route_config.md b/docs/customization/route_config.md index 01f59c412..0e69dfb80 100644 --- a/docs/customization/route_config.md +++ b/docs/customization/route_config.md @@ -1,6 +1,10 @@ # Customizing Routes -If you need to customize how any of the auth features are handled, you will likely need to update the routes to point to the correct controllers. You can still use the `service('auth')->routes()` helper, but you will need to pass the `except` option with a list of routes to customize: +## Change Some Routes + +If you need to customize how any of the auth features are handled, you will likely need to update the routes to point to the correct controllers. + +You can still use the `service('auth')->routes()` helper, but you will need to pass the `except` option with a list of routes to customize: ```php service('auth')->routes($routes, ['except' => ['login', 'register']]); @@ -12,3 +16,36 @@ Then add the routes to your customized controllers: $routes->get('login', '\App\Controllers\Auth\LoginController::loginView'); $routes->get('register', '\App\Controllers\Auth\RegisterController::registerView'); ``` + +After customization, check your routes with the [spark routes](https://codeigniter.com/user_guide/incoming/routing.html#spark-routes) command. + +## Use Locale Routes + +You can use the `{locale}` placeholder in your routes +(see [Locale Detection](https://codeigniter.com/user_guide/outgoing/localization.html#in-routes)). + +```php +$routes->group('{locale}', static function($routes) { + service('auth')->routes($routes); +}); +``` + +The above code registers the following routes: + +```text ++--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ +| Method | Route | Name | Handler | Before Filters | After Filters | ++--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ +| GET | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerView | session | toolbar | +| GET | {locale}/login | login | \CodeIgniter\Shield\Controllers\LoginController::loginView | session | toolbar | +| GET | {locale}/login/magic-link | magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView | session | toolbar | +| GET | {locale}/login/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | session | toolbar | +| GET | {locale}/logout | logout | \CodeIgniter\Shield\Controllers\LoginController::logoutAction | session | toolbar | +| GET | {locale}/auth/a/show | auth-action-show | \CodeIgniter\Shield\Controllers\ActionController::show | session | toolbar | +| POST | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | session | toolbar | +| POST | {locale}/login | » | \CodeIgniter\Shield\Controllers\LoginController::loginAction | session | toolbar | +| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | session | toolbar | +| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | session | toolbar | +| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | session | toolbar | ++--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ +``` From d22564066880a9cdff9f13d1d7b368ff2fb4fa96 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 9 Oct 2023 09:47:11 +0900 Subject: [PATCH 2/2] docs: add about global filter config update --- docs/customization/route_config.md | 35 ++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/docs/customization/route_config.md b/docs/customization/route_config.md index 0e69dfb80..46d1c6597 100644 --- a/docs/customization/route_config.md +++ b/docs/customization/route_config.md @@ -36,16 +36,29 @@ The above code registers the following routes: +--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ | Method | Route | Name | Handler | Before Filters | After Filters | +--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ -| GET | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerView | session | toolbar | -| GET | {locale}/login | login | \CodeIgniter\Shield\Controllers\LoginController::loginView | session | toolbar | -| GET | {locale}/login/magic-link | magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView | session | toolbar | -| GET | {locale}/login/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | session | toolbar | -| GET | {locale}/logout | logout | \CodeIgniter\Shield\Controllers\LoginController::logoutAction | session | toolbar | -| GET | {locale}/auth/a/show | auth-action-show | \CodeIgniter\Shield\Controllers\ActionController::show | session | toolbar | -| POST | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | session | toolbar | -| POST | {locale}/login | » | \CodeIgniter\Shield\Controllers\LoginController::loginAction | session | toolbar | -| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | session | toolbar | -| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | session | toolbar | -| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | session | toolbar | +| GET | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerView | | toolbar | +| GET | {locale}/login | login | \CodeIgniter\Shield\Controllers\LoginController::loginView | | toolbar | +| GET | {locale}/login/magic-link | magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::loginView | | toolbar | +| GET | {locale}/login/verify-magic-link | verify-magic-link | \CodeIgniter\Shield\Controllers\MagicLinkController::verify | | toolbar | +| GET | {locale}/logout | logout | \CodeIgniter\Shield\Controllers\LoginController::logoutAction | | toolbar | +| GET | {locale}/auth/a/show | auth-action-show | \CodeIgniter\Shield\Controllers\ActionController::show | | toolbar | +| POST | {locale}/register | register | \CodeIgniter\Shield\Controllers\RegisterController::registerAction | | toolbar | +| POST | {locale}/login | » | \CodeIgniter\Shield\Controllers\LoginController::loginAction | | toolbar | +| POST | {locale}/login/magic-link | » | \CodeIgniter\Shield\Controllers\MagicLinkController::loginAction | | toolbar | +| POST | {locale}/auth/a/handle | auth-action-handle | \CodeIgniter\Shield\Controllers\ActionController::handle | | toolbar | +| POST | {locale}/auth/a/verify | auth-action-verify | \CodeIgniter\Shield\Controllers\ActionController::verify | | toolbar | +--------+----------------------------------+--------------------+--------------------------------------------------------------------+----------------+---------------+ ``` + +If you set the global filter in the **app/Config/Filters.php** file, you need to +update the paths for `except`: + +```php +public $globals = [ + 'before' => [ + // ... + 'session' => ['except' => ['*/login*', '*/register', '*/auth/a/*']], + ], + // ... +]; +```