Skip to content

Commit

Permalink
Merge pull request #1251 from datamweb/docs-require-Activator-in-clas…
Browse files Browse the repository at this point in the history
…s-name

docs: require `activator` in custom actions class name for `register`
  • Loading branch information
datamweb authored Feb 15, 2025
2 parents 58d6d6f + 7c1ab83 commit e782eb0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/references/authentication/auth_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ public $views = [
## Defining New Actions

While the provided email-based activation and 2FA will work for many sites, others will have different
needs, like using SMS to verify or something completely different. Actions have only one requirement:
they must implement `CodeIgniter\Shield\Authentication\Actions\ActionInterface`.
needs, like using SMS to verify or something completely different. Custom actions must adhere to the following requirements:

The interface defines three methods for `ActionController`:
1. The class name for a "register" action must end with the suffix `Activator` (e.g., `SMSActivator`) to ensure consistency.
2. All custom actions must implement the `CodeIgniter\Shield\Authentication\Actions\ActionInterface`.

The `ActionInterface` defines three required methods that must be implemented to ensure the action integrates properly with the `ActionController`.

**show()** should display the initial page the user lands on immediately after the authentication task,
like login. It will typically display instructions to the user and provide an action to take, like
Expand All @@ -76,4 +78,4 @@ and provides feedback. In the `Email2FA` class, it verifies the code against wha
database and either sends them back to the previous form to try again or redirects the user to the
page that a `login` task would have redirected them to anyway.

All methods should return either a `Response` or a view string (e.g. using the `view()` function).
All methods should return either a `Response` or a view string (e.g. using the `view()` function).
5 changes: 5 additions & 0 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ class Auth extends BaseConfig
* - register: \CodeIgniter\Shield\Authentication\Actions\EmailActivator::class
* - login: \CodeIgniter\Shield\Authentication\Actions\Email2FA::class
*
* Custom Actions and Requirements:
*
* - All actions must implement \CodeIgniter\Shield\Authentication\Actions\ActionInterface.
* - Custom actions for "register" must have a class name that ends with the suffix "Activator" (e.g., `CustomSmsActivator`) ensure proper functionality.
*
* @var array<string, class-string<ActionInterface>|null>
*/
public array $actions = [
Expand Down

0 comments on commit e782eb0

Please sign in to comment.