- I want to login customer from external Laravel App to magento site.
- I have multi store multi website setup (mean every store have separate website)
I try all available ways:
1) By importing Magento OM in Laravel app & try to login like its successfully authenticating the customer but on refreshing the Magento page customer not log in:
$store = $this->_objManager->create('Magento\Store\Model\Store')->load($storeId);
// Load customer
$customer = $this->_objManager->create('Magento\Customer\Model\Customer')->setStore($store);
if($customer->authenticate($email, $password)){
$customerSession = $this->_objManager->create('Magento\Customer\Model\Session');
$customerSession->loginById($customer->getId());
$customerSession->regenerateId();
if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
$metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
$metadata->setPath('/');
$this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
}
if($customerSession->isLoggedIn()) {
echo $customer->getId(). "----Customer Logged in";
}else{
echo "customer is Not Logged in";
}
}
In above case in Laravel controller printing: 145----Customer Logged in mean code wise I am getting customer session created properly in Laravel App. But on Magento site page reload customer not login.
2) I Also Try LoginPost Method:
I post ajax request from Laravel form
xhttp.open("POST", "http://ie.domainName.com/customer/account/loginPost/", false);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("Content-length", params.length);
xhttp.setRequestHeader("Connection", "close");
xhttp.send(params);
to this controller same its authenticating the customer and & I get customers id in the execute function after authentication. But here as well when I try to reload Magento page in same browser its not login customer. What I am missing here ?
'customer/account/loginPost' customer can login successfully & diverted to customer dash board but in above through Ajax post its not working. – Hassan Ali Shahzad Feb 13 '19 at 14:26