AnswerBun.com

Magento 2 get Admin session in frontend

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

Magento Asked by Ramesh on December 29, 2020

1 Answers

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!

Related Questions

Get matrixrate config programatically

0  Asked on December 14, 2020 by pevik

     

Error 404 : The requested page do not exist

1  Asked on December 14, 2020 by claims

   

Magento 2 Checkout shipping afterRender

0  Asked on December 13, 2020 by mac_mod

         

How to make checkout page 2columns-left on magento 2

1  Asked on December 13, 2020 by alin-lupoiu

       

magento2 plugin and str_replace

2  Asked on December 11, 2020 by boll

 

Custom email layout handle for custom module

2  Asked on December 11, 2020 by karan-adhikari

     

Magento 2 – Remove debug path hint from email template

3  Asked on December 9, 2020 by hardik

   

Watermark magento 2

2  Asked on December 9, 2020 by pascal-van-kooten

 

How to place sizes in order

1  Asked on December 7, 2020 by stefaniiia

 

Magento 2.4 disable UI/Theme part

0  Asked on December 7, 2020 by bogdan-hepting

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.