2

I am working with the Magento REST API.

I have developed a service for users to sign in, and that works fine. But when I call the service and try to load the Magento front end, I can't see the logged in user information. User session is not retaining.

I want to use the same user session of the user logged in via REST.

Can any one help me to fix this?

$session = Mage::getSingleton('customer/session', array("name"=>"frontend"));
$session->login($email, $password);

if ($session->isLoggedIn()) {
    $session->setCustomerAsLoggedIn( $session->getCustomer() );
    $customer = Mage::getModel("customer/customer")
                        ->setWebsiteId(Mage::app()->getWebsite()->getId())
                        ->loadByEmail($email);

    if ($customer->getId()) {
        $customerData = $this->_getCustomerDetails($customer);
        Mage::getSingleton('customer/session')->unsCustomerLoginCnt();
    } else {
        $this->getResponse()->setHeader('HTTP/1.0', Yamaha_Api2_Model_Server::HTTP_NOT_FOUND, true);       
        $message = 'Customer Information Currenlty Unavailable';                    
    }
}
2
  • it is magento...
    – ivantedja
    Aug 11, 2015 at 15:27
  • Session sharing is not supported between web APIs and browser in Magento, these are 2 independent sessions. Nov 10, 2015 at 14:42

1 Answer 1

2

As Alex mentioned here earlier: Session sharing is not supported between REST and the frontend.

I'm not quite sure where you put the code above and what unsCustomerLoginCnt does so you will need to update your question if you still need help.


For future readers:

How to achieve this?

What needs to be done is to set the session received via REST API as a session cookie with the right domain to the browser. Then you should be able to access that session and be logged in.

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.