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("test@m2s.com"); 

  • Can you please upload your full code ? – Rohan Hapani Jul 30 '19 at 6:49

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.

| improve this answer | |

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.