Disabling redirecting after customer login magento

Disabling redirecting after customer login magento

July 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Disabling redirecting after customer login magento

Disabling Customer Redirect after Login in Magento

As a Magento developer, I often receive requests like this from merchants who want their customers to stay on the same page after logging into their accounts. By default, Magento redirects users to the account dashboard after successful login. However, there is indeed a simple way to achieve your desired behavior using some custom code.

Understanding the Default Behavior

The redirect issue you’re experiencing when disabling the “Redirect customer to Account Dashboard” setting in System > Configuration > Customers > Customer Configuration > Login Options likely stems from Magento’s core login functionality. When a user logs in, the system processes the login request and then redirects them to the dashboard view.

Disabling the Redirect

To keep customers on their current page after logging in, we need to override this default behavior without using extensions like Psycho. Here’s how you can do it:

  1. Create an observer for controller_action_predispatch

First, let’s create a new module and an observer that will intercept the login post action before it redirects.

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="LaravelCompany_CustomLogin" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Customer"/>
        </sequence>
    </module>
</config>
  1. Create the observer

Next, create an observer that will be triggered when the customer_account_loginPost event is dispatched.

class LoginPostObserver implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($this->isLoginRequest($observer)) {
            $controller = $observer->getControllerAction();
            $controller->setNoCache(true);
            $controller->getResponse()->setRedirectUrl($controller->getFullActionName());
        }
    }

    private function isLoginRequest(\Magento\Framework\Event\Observer $observer)
    {
        return $observer->getControllerAction()->getRequest()->isPost();
    }
}
  1. Configure your observer

In your module’s etc/di.xml file, add the following to configure your observer:

<type name="Magento\Framework\View\Result\Page">
    <arguments>
        <argument name="design" xsi:type="array">
            <item name="allowed_areas" xsi:type="string">frontend</item>
        </argument>
    </arguments>
</type>

<virtualType name="LaravelCompany_CustomLogin\Model\Observer\LoginPostObserver"
             type="Magento\Framework\Observer">
    <constructor>
        <argument index="0">
            <type name="Magento\Framework\App\Request\Http" />
        </argument>
    </constructor>
    <arguments>
        <argument name="request" xsi:type="object">Magento\Framework\App\Request\Http</argument>
        <argument name="responseFactory" xsi:type="object">Magento\Framework\View\Result\ResponseFactory</argument>
    </arguments>
</virtualType>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <event name="customer_account_loginPost">
        <observer name="laravelcompany_customlogin_loginpost_observer"
                  instance="LaravelCompany_CustomLogin\Model\Observer\LoginPostObserver"
                  shared="false" />
    </event>
</config>

Conclusion

By following these steps, you should be able to override the default login redirection behavior and keep customers on their current page after a successful login. It’s important to ensure your code aligns with Magento’s best practices for observers and event handling.

Remember, when working with core files or creating customizations in Magento, always use a development environment to avoid potential issues affecting your live site. If you’re unsure about any part of the process, don’t hesitate to reach out to our expert team at Laravel Company.

Cache Security Extensions Configuration

Our network