Use below code for check user login or no
protected $_session;
protected $_context;
protected $objectManager;
public function __construct(
\Magento\Customer\Model\Session $session,
\Magento\Framework\View\Element\Template\Context $context
) {
parent::__construct($context);
$this->objectManager = $context->getObjectManager();
}
public function isCustomerLoggedIn()
{
$session = $this->objectManager->get('Magento\Customer\Model\Session');
if($session->isLoggedIn()) {
$status = "Customer logged in";
}else{
$status = "Not customer logged in";
}
return $status;
}
Also you can use check user login or not using cookies
define(['Magento_Customer/js/model/customer'],
function(customer) {
return Component.extend({
someMethod: function () {
if (customer.isLoggedIn()) {
//do smth
} else {
//do smth
}
},
});
}
);
Get Reference