0

we use have some configurations to some user groups (different prices, only some categories etc) and it's all good if the customer logout and login as a different group account, but when it auto logs out after sometime the cookies stay so the customer see in our website the group restrict config as a logged out customer. It's a bit difficult to explain but what I need is to delete the cookies that are created when the customer login when the account logs out by the end of session lifetime.

Is there anything we can do to make this work?

Best regards, Rui Silva

0

In default Magento, the cookie is deleted once the customer logout. Please check that if you have customised logout action then you must have delete cookie by deleteCookie function of Magento\Framework\Stdlib\Cookie\PhpCookieManager class

Here is the code of default logout action

vendor/magento/module-customer/Controller/Account/Logout.php

public function execute()
{
    $lastCustomerId = $this->session->getId();
    $this->session->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())
        ->setLastCustomerId($lastCustomerId);
    if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
        $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
        $metadata->setPath('/');
        $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
    }

    /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
    $resultRedirect = $this->resultRedirectFactory->create();
    $resultRedirect->setPath('*/*/logoutSuccess');
    return $resultRedirect;
}
1
  • Hey, all seems fine, and I did further testing and I got it wrong there, if I logout manually it's all fine, only if it reaches the end of the lifetime that happens the error and the cookies are not cleared, I'll change in the question sorry
    – Rui Silva
    Apr 29 at 8:55

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.