1


How can I login customer in specific store programmatically in Magento 2?
I've tried to override execute method of

Magento\Customer\Controller\Account\LoginPost

and did something like this:

$this->storeManager->setCurrentStore("store_code");
$store = $this->storeRepository->getActiveStoreByCode("store_code");
$this->httpContext->setValue("store", "store_code", "default");
$this->storeCookieManager->setStoreCookie($store);

$customer = $this->customerAccountManagement->authenticate($login['username'], $login['password']);
$this->session->setCustomerDataAsLoggedIn($customer);

But it didn't work.

I need to do main store, where customer will insert his credentials, and after that customer will logged in and redirected to store according to his customer group

  • why you don't use account share at option? – Amit Bera Oct 2 '18 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.