TransWikia.com

Magento 2 get Admin session in frontend

Magento Asked by Ramesh on December 29, 2020

How can i get the admin session in frontend.

   $objectManager = MagentoFrameworkAppObjectManager::getInstance();
   $adminSession = $objectManager->create('MagentoSecurityModelAdminSessionsManager');
   print_r($adminSession->getCurrentSession()->getStatus());

I tried with above script but no luck

One Answer

protected $_session;

public function __construct(
    MagentoFrameworkModelContext $context,
    MagentoBackendModelAuthSession $authSession
) {
    $this->_session = $authSession;

    parent::__construct($context);
}

and then call

$this->_session->isLoggedIn()

Note: don't use objectManager. Its not proper way to do it in Magento 2

Answered by Abhishek Panchal on December 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP