In an Admin Controller Class, How do I check if the admin user is logged in, then redirect to the login page if not logged in, then return to the previous controller after login?
A cut down version of my script as follows.
use MagentoFrameworkViewResultPage;
use MagentoFrameworkControllerResultRedirect;
class Index implements HttpGetActionInterface
{
/* Constructor */
public function execute(): Page|Redirect
{
if (!$this->_isAllowed()) {
### How and where to redirect here? ###
}
/* Do stuff here and load Index page */
}
}
Not sure if “$this->_isAllowed()” is the correct method to use to check if an admin user is logged in?
Not sure where/how to redirect if user not logged in, or session has ended.
Advice on the correct Magento way to do this would be appreciated.