I have Need to run some script after logged in admin user in magento 2.

But, Its not calling for me.

What i did:

I have created js file this location.



    ], function($){

        console.log('user logged  in');

Then create my Observer:




    namespace Vendor\Module\Observer;

    use Magento\Framework\Event\ObserverInterface;

    class BackendAuthUserLoginSuccess implements ObserverInterface

        protected $logger;

        protected $_request;

        protected $authSession;

        public function __construct(
            \Psr\Log\LoggerInterface $logger,
            \Magento\Framework\App\RequestInterface $request,
            \Magento\Backend\Model\Auth\Session $authSession

            $this->logger = $logger;
            $this->_request = $request;
            $this->authSession = $authSession;


        public function execute(\Magento\Framework\Event\Observer $observer)

            if ($this->authSession->getUser()->getAclRole() == 4) { ?>

                <script type="text/x-magento-init">
                        "*": {

                <?php $this->logger->addDebug($this->authSession->getUser()->getEmail());

After Called this Observer, its does not call this x-magento-init

Suggest me, What's problem in this code and how to fix this.

1 Answer 1


I have never used this method for adminhtml but I presume it's the same as on the frontend, in which case you're missing js from your path. Try changing



  • its not works for me Oct 3, 2017 at 13:57
  • Damn it, that's my only input as I'm a front-end dev so I can't help with the rest of the code sorry. I still think this is correct though so hopefully it helps once the main issue is resolved. Good luck!
    – Ben Crook
    Oct 3, 2017 at 13:59

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.