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.
app/code/Vendor/Module/view/adminhtml/web/js/seo_field.js
seo_field.js
define([
"jquery"
], function($){
console.log('user logged in');
});
Then create my Observer:
app/code/Vendor/Module/Observer/BackendAuthUserLoginSuccess.php
BackendAuthUserLoginSuccess.php
<?php
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">
{
"*": {
"Vendor_Module/js/seo_field":{}
}
}
</script>
<?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.