How Can I Login Magento 2 Customer Account Programmatically

How can I login Magento 2 customer account programmatically

You can use “setCustomerAsLoggedIn” method to login Magento 2 customer account programmatically

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer = $objectManager->create('Magento\Customer\Model\Customer')->load(1); //2 is Customer ID
$customerSession = $objectManager->create('Magento\Customer\Model\Session');
$customerSession->setCustomerAsLoggedIn($customer);
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments