Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion docs/customization/route_config.md
Original file line number Diff line number Diff line change
@@ -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']]);
Expand All @@ -12,3 +16,49 @@ 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
Copy link
Collaborator

@datamweb datamweb Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the way to use the following items does not change?

public array $redirects = [
'register' => '/',
'login' => '/',
'logout' => 'login',
'force_reset' => '/',
];

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

login is a named route, so not change.

(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 | | 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/*']],
],
// ...
];
```