How to login a user with an E-mail to magento2 site without triggering event customer_login.

Actually, I am able to login with email using customer session but the customer session also triggers the customer_login events.

I don't want to use a trigger.

$customer = $this->_customer->loadByEmail("[email protected]"); 

  • Can you please upload your full code ? Commented Jul 30, 2019 at 6:49

1 Answer 1


To modify any default functionality of magento you can simply override it's class.

Use this reference to do the same.

In this case you have to override this method.


Remove the line from setCustomerAsLoggedIn() function which trigger 'customer_login' event.

 $this->_eventManager->dispatch('customer_login', ['customer' => $customer]);

Your function setCustomerAsLoggedIn will look like this.

 public function setCustomerAsLoggedIn($customer)
    $this->_eventManager->dispatch('customer_data_object_login', ['customer' => $this->getCustomerDataObject()]);
    return $this;

I hope it will helps you. And let me know if you need further help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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