cancel
Showing results for 
Search instead for 
Did you mean: 

customer_data not loaded on custom login controller in Magento 2.3.4 and 2.3.5

customer_data not loaded on custom login controller in Magento 2.3.4 and 2.3.5

I have a SSO module with a custom login controler.

After login, when the main page is loaded, the customer_data is not available on js.

I read the private content documentation and I'm already invalidating the private content by a
Vendor/ModuleName/etc/frontend/sections.xml file

I created a GitHub issue here describing the issue in detail:
https://github.com/magento/magento2/issues/28428

Can someone help? It seems it affects more people.

2 REPLIES 2

Re: customer_data not loaded on custom login controller in Magento 2.3.4 and 2.3.5

Had similar issue.

In file vendor/magento/module-customer/Controller/Account/LoginPost.php

there is a code piece you've probably forgot to add to your custom login action:

if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
    $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
    $metadata->setPath('/');
    $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
}

However, it should work fine without this code as it is deprecated.

 

Another reason could be that you've named your custom action in sections.xml wrong - there should be a front name, not a route ID.

Re: customer_data not loaded on custom login controller in Magento 2.3.4 and 2.3.5

The issue was related to the fact that customerData was not invalidated before execute the login process.


In the normal login flow, when user introduces credentials and click on submit, there is a js that is executed on such submit action that invalidates the CustomerData.

    $(document).on('submit', function (event) {
        var sections;

        if (event.target.method.match(/post|put|delete/i)) {
            sections = sectionConfig.getAffectedSections(event.target.action);

            if (sections) {
                customerData.invalidate(sections);
            }
        }
    });


It seems that on Magento > 2.3 CustomerData must be invalidated before log in a new user, otherwise customer data is not loaded in the frontend (js) when user log in on backend.