I have created custom form and create custom controller if customer is LoggedIn, then if anyone try to do registration then it requires to show the error message, how can i do that?

  • @sumit if you know please let me know – Magento Aug 29 '19 at 11:25
  • can you add your code here what you have tried so far? – Balwant Singh Aug 29 '19 at 11:36

Try This

use Magento\Customer\Model\Customer;
use Magento\Customer\Model\CustomerFactory;
use Magento\Customer\Model\Session;

 * Class Index
class Index extends \Magento\Framework\App\Action\Action

 * @param \Magento\Framework\App\Action\Context
 * @param Customer
public function __construct(
    \Magento\Framework\App\Action\Context $context,
    Session $customerSession,
) {
    $this->customerSession   = $customerSession;
public function execute()
            if ($this->customerSession->isLoggedIn()) {
                $this->messageManager->addWarning('User is loggedIn');
                return $resultRedirect;
        } else {
            $this->messageManager->addWarning('User Not loggedIn');
            return $resultRedirect;


Other Funtions in Message Manager

  1. addWarning
  2. addSucces
  3. addError

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.