Hi all,
I’m running into a problem with a site which I just upgraded from v4 to v5. Within the site controller I check if a user browsing any of pages is already logged in. If not then they’re being redirected to the login page. However after upgrading to v5 this results in endless redirects to page login. Below is what I currently have.. does anyone notice something I’m doing wrong here?
controllers/site.php
<?php
use MyApp\Handler\AccessHandler;
return function () {
/**
* Check if the user is logged in
*/
AccessHandler::isUserLoggedIn();
site/plugins/MyApp/lib/App/Handler/AccessHandler.php
/**
* Verify if a user is logged in
*
* @return void
*/
public static function isUserLoggedIn(): void
{
$kirby = kirby();
$page = page();
// Skip auth check on login page
if($page->id() === 'login') return;
// If there is no user, they are denied access
if(!$kirby->user()) {
go('/login');
}
}
Edit: My goal is to redirect the user to the login page /login if the user is not logged in yet.