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

1 Answer 1


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


public function execute()
    $lastCustomerId = $this->session->getId();
    if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
        $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
        $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);

    /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
    $resultRedirect = $this->resultRedirectFactory->create();
    return $resultRedirect;
  • 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
    Commented Apr 29, 2021 at 8:55

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.