I want to write a script for redirection, i would like to write this script in Magento 2 header.phtml file, i have tried this below method but it is going to an infinite loop. Any one have any idea about this?
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('\Magento\Customer\Model\Session'); $urlInterface
= $objectManager->get('\Magento\Framework\UrlInterface');
if(!$customerSession->isLoggedIn()) {
$customerSession->setAfterAuthUrl($urlInterface->getCurrentUrl());
$customerSession->authenticate(); }
Router.php
?