I have observer of backend_auth_user_login_success.

I need the data of the admin user who is login in observer.

Can anyone please help me into this?

Thanks in advance.

  • By using \Magento\Backend\Model\Auth\Session $authSession you can get the current logged in admin user details without the observer. Ex: $this->authSession->getUser(); – Bhaumik 1987 May 29 at 16:47

You can create events.xml file here in your module


Content for this file is..

<?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="backend_auth_user_login_success_observer" instance="Vendor\Module\Observer\BackendAuthObserver" />

Now create Observer file here


namespace Vendor\Module\Observer;

class BackendAuthObserver implements \Magento\Framework\Event\ObserverInterface
    public function execute(\Magento\Framework\Event\Observer $observer)
        $user = $observer->getEvent()->getUser();

        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/backend_auth_user_login_success.log');
        $logger = new \Zend\Log\Logger();

        return $this;

Run below commands once

php bin/magento setup:upgrade
php bin/magento cache:clean

Now Go to your Backend and try to login with your username and password, and navigate to your var/log directory you can see backend_auth_user_login_success.log file there with your user content.

Hope this will help you!

| improve this answer | |
  • 1
    Perfect answer. It helps lot. Thanks – Mayur Sisodiya May 29 at 18:16
  • @MayurSisodiya, Welcome Buddy. :-) – Kishan Savaliya May 30 at 2:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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