Back to Top

Get Admin Logged-In Status from Frontend in Mage Adobe Commerce (Magento 2)

Updated 4 September 2024

Here we learn, how to know the admin logged in status from frontend in Adobe Commerce (Magento 2).

Write the below code where ever you need to know the admin logged in status from frontend in Adobe Commerce (Magento 2).

public function isAdminloggedIn()
{
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $dateTime = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime');
    $adminConfig = $objectManager->create('Magento\Security\Model\Config');
    $lifetime = $adminConfig->getAdminSessionLifetime();
    $currentTime = $dateTime->gmtTimestamp();
    $adminSession = $objectManager->create('Magento\Security\Model\AdminSessionsManager');
    $lastUpdatedTime = $dateTime->gmtTimestamp($adminSession->getCurrentSession()->getUpdatedAt());
    if (!is_numeric($lastUpdatedTime)) {
        $lastUpdatedTime = strtotime($lastUpdatedTime);
    }
    if ($lastUpdatedTime >= ($currentTime - $lifetime)
        && $adminSession->getCurrentSession()->getStatus() == 1
        && $adminSession->getCurrentSession()->getUserId()
    ) {
        return true;
    } else {
        return false;
    }
}

If you require any technical help, please email us at [email protected]. Additionally, browse various solutions to improve your store’s functionality by visiting the Adobe Commerce plugins page.

For expert consultation or to develop custom features, Hire Adobe Commerce Developers for your project.

That’s it.

Start your headless eCommerce
now.
Find out More
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Manup
  • Manoj Pal
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home