Postlogin.php
<?php
namespace Mycompany\Customerhomepage\Plugin;
use Magento\Framework\Controller\ResultFactory;
class Postlogin
{
public function __construct(
\Magento\Framework\UrlInterface $url,
\Magento\Framework\App\Response\Http $response,
ResultFactory $resultFactory
) {
$this->_url = $url;
$this->_response = $response;
$this->resultFactory = $resultFactory;
}
public function afterExecute(\Magento\Customer\Controller\Account\LoginPost $subject , $result)
{
$customerBeforeAuthUrl = $this->_url->getUrl('customerhomepage/index/landing');
$this->_response->setRedirect($customerBeforeAuthUrl)->sendResponse();
}
}
di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Customer\Controller\Account\LoginPost">
<plugin name="Mycompany_Plugin_Postlogin" type="Mycompany\Customerhomepage\Plugin\Postlogin"></plugin>
</type>
</config>
I want to redirect to a custom page after login , how to do that by plugin ?
UPDATE
The Code Works fine it redirects to Custom page , as soon as the website restrictions are on it stop working