In Magento 1 below code works
Mage::getSingleton('core/session', array('name' => 'adminhtml'));
$adminSession = Mage::getSingleton('admin/session');
if ($adminSession->isLoggedIn()) {
$adminIpAddress = $adminSession['_session_validator_data']['remote_addr'];
}
I am trying below code in magento 2 that is working in admin section but not working on frontend
$adminSession= $this->auth->isLoggedIn();
including (\Magento\Backend\Model\Auth)
I need to check if admin is logged in or not on front end in magento2
Any help will be appreciated.
Solved! Go to Solution.
What I found in my quick research is:
In magento 1 it was quite easy to get the admin session on frontend since magento had no restrictions when it expose the admin session cookie.
But in magento2, the admin cookie will get exposed only for the admin path, for example /admin, because of this, you won't be able to access the admin session on frontend.
But as an alternate solution, you can try:
What I found in my quick research is:
In magento 1 it was quite easy to get the admin session on frontend since magento had no restrictions when it expose the admin session cookie.
But in magento2, the admin cookie will get exposed only for the admin path, for example /admin, because of this, you won't be able to access the admin session on frontend.
But as an alternate solution, you can try: