Question

What are the steps in magento 2 to use the events to capture the admin login success or admin login fail.

Was it helpful?

Solution

You can observe the following events:

  • admin user login success: backend_auth_user_login_success
  • admin user login fail: backend_auth_user_login_failed

In a module you can create the following etc/events.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="backend_auth_user_login_success">
        <observer name="my_custom_login_success_observer" instance="Vendor\Module\Observer\AdminLoginSucceeded" />
    </event>
    <event name="backend_auth_user_login_failed">
        <observer name="my_custom_login_failed_observer" instance="Vendor\Module\Observer\AdminLoginFailed" />
    </event>
</config>

Then you can create the following observers:

  • Observer/AdminLoginSucceeded.php
  • Observer/AdminLoginFailed.php
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top