I'm a Magento 2 newbie. In my site we have 2 store- default and wholesale.

Account Login to default store will be like this - http://example.com/customer/account/login/ and for wholsesale store http://example.com/wholesale/customer/account/login

When I try to login to two store using different account from same browser it will work, but when I try to logout from one store it logging me out from another store also. How I can prevent this. I need to keep logging me in another(wholesale) store even if I logged out from default store.

I need this to work on same browser.

I created a module and tried to override logout action.

This is my code:


namespace Customvendor\Custommodule\Controller\Customer;

use Magento\Customer\Model\Session;
use Magento\Framework\App\Action\Context;
use \Magento\Framework\Controller\ResultFactory;

class Logout extends \Magento\Framework\App\Action\Action
     * @var Session
    protected $customerSession;

    public function __construct(
        Context $context,
        Session $customerSession
    ) {
        //$this->session = $customerSession;
        $this->redirect = $context->getRedirect();
        $this->customerSession = $customerSession;

    public function execute() {
        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        $customerId = $this->customerSession->getId();
        if($customerId) {
            //echo $customerId;exit;
            $this->messageManager->addSuccess(__('Logout successfully'));
            return $resultRedirect->setPath('customer/account/login/');  
        } else {
            $this->messageManager->addSuccess(__('Customer is not logged in'));
            return $resultRedirect->setPath('customer/account/login/');


Please help me to fix this issue. Thanks in advance


1 Answer 1


what you can do, you need to create a new extension and override the logout controller and event. There before logging out, you need to fetch the website ID, and use the logout event for that website only just like Magento does in case of "Per website" account sharing option and prevent magento logout event, which will be global in your case.

  • I've added my code in question. How can I add websiteID basis condition? Commented Sep 6, 2019 at 7:31
  • It is there in default Magento when per website is enabled. Magento generate cache based on that. Give me some time to find out. Commented Sep 6, 2019 at 7:34

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.