Skip to content
Magento / Adobe Commerce · 1 min read · Published Nov 18, 2019 · ✓ Updated Nov 2025

Check if Customer is Logged in or not in Magento 2

MK
Mitali Kundale

As we all know, there are so many conditions where we need to check whether the customer is currently logged in or not for specific functionality. In this blog post, you will have an idea about How to check Magento 2 Customers login or not in Magento 2?

It is always best practice to don’t use ObjectManager directly. You can use the following code to check whether the user is logged in or not in any class except template files.

You need to use this Magento\Customer\Model\Session::isLoggedIn() method in following way.  First, you need to inject the following class in your constructor: /Magento/Customer/Model/Session.

  
protected $_session;

public function __construct(
    ...
    \Magento\Customer\Model\Session $session,
    ...
) {
    ...
    $this->_session = $session;
    ...
}

Then in your class, you can use the following snippet of code anywhere.

if ($this->_session->isLoggedIn()) {
    // Customer is logged in 
} else {
    // Customer is not logged in
}

This was how to check Magento 2 Customers login status. Hope you found it useful.

Written & reviewed by
MK
Mitali Kundale
Questions? Reach out via StageBit's consultation page.

Tell us more about your brand!

Rohit Kundale, Our VP of Sales and Marketing is ready to meet with your team.