Shield fires off several events during the lifecycle of the application that your code can tap into.
When you want to respond to an event that Shield publishes, you will need to add it to your app/Config/Events.php file. Each of the following events provides a sample for responding that uses a class and method name. Other methods are available. See the CodeIgniter 4 User Guide for more information.
Triggered when a new user has registered in the system. The only argument is the User entity itself.
Events::trigger('register', $user);
Events::on('register', 'SomeLibrary::handleRegister');Fired immediately after a successful login. The only argument is the User entity.
Events::trigger('login', $user);
Events::on('login', 'SomeLibrary::handleLogin');Triggered when a login attempt fails. It provides an array containing the credentials the user attempted to sign in with, with the password removed from the array.
// Original credentials array
$credentials = ['email' => 'foo@example.com', 'password' => 'secret123'];
Events::on('failedLogin', function($credentials) {
dd($credentials);
});
// Outputs: ['email' => 'foo@example.com'];When the magic login fails, the following array will be provided:
['magicLinkToken' => 'the token value used']Fired immediately after a successful logout. The only argument is the User entity.
Fired when a user has been successfully logged in via a magic login. This event does not have any parameters passed in. The authenticated user can be discovered through the auth() helper.
Events::on('magicLogin', function() {
$user = auth()->user();
//
})To learn more about Event timing, please see the list below.