customerUrl = $customerUrl; $this->customerSession = $customerSession; } /** * Authenticate user * * @param \Magento\Framework\App\ActionInterface $subject * @param RequestInterface $request * @return void * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function beforeDispatch(\Magento\Framework\App\ActionInterface $subject, RequestInterface $request) { $loginUrl = $this->customerUrl->getLoginUrl(); if (!$this->customerSession->authenticate($loginUrl)) { $subject->getActionFlag()->set('', $subject::FLAG_NO_DISPATCH, true); } } }