5

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

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.