I have a custom module index page where I'm creating a session for a particular user and redirecting to the home page.


$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customer = $objectManager->create('Magento\Customer\Model\Customer')->load(8857);
$createCustomerSession = $objectManager->create('Magento\Customer\Model\Session');

if ($createCustomerSession->isLoggedIn()) {
print_r(' Logged in? ' . $createCustomerSession->isLoggedIn());exit;

When I hit {BASE_URL}/index.php/login, It returns me the customerId and Logged in? 1 (i.e. the customer is logged in) but if I remove exit from the print statement, its redirecting to home page but the user is not logged in. I could see the Sign In and Create an Account buttons.

Customer is not logged in on any other pages too. How is the session getting cleared?

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.