customerSession = $customerSession; $this->resultJsonFactory = $resultJsonFactory; } /** * Customer logout action * * @return \Magento\Framework\Controller\Result\Json */ public function execute() { $lastCustomerId = $this->customerSession->getId(); $this->customerSession->logout() ->setBeforeAuthUrl($this->_redirect->getRefererUrl()) ->setLastCustomerId($lastCustomerId); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultJsonFactory->create(); return $resultJson->setData(['message' => 'Logout Successful']); } }