I have created customer dashboard custom tab and the path is 'inquiry/customer/
' which is working fine.
Issue is that If the user hit the direct that url in the browser without login in his account then user is getting an error.
I want to redirect the user to login page if he is not logged in.
How can I do?
My Code:
customer_account.xml:
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-inquiry-link">
<arguments>
<argument name="label" xsi:type="string" translate="true">My Question</argument>
<argument name="path" xsi:type="string">inquiry/customer</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Controller:
<?php
namespace Vendor\Inquiry\Controller\Customer;
class Index extends \Magento\Framework\App\Action\Action
{
/**
* Index Action*
* @return void
*/
public function execute()
{
$this->_view->loadLayout();
$this->_view->renderLayout();
}
}