It's good practise to extend from a baseController
and implement some base functions
implement a function to check if the user instance is null like this
if the user form the Userinterface
then there is no user logged in
/**
*/
class BaseController extends AbstractController
{
/**
* @return User
*/
protected function getUser(): ?User
{
return parent::getUser();
}
/**
* @return bool
*/
protected function isUserLoggedIn(): bool
{
return $this->getUser() instanceof User;
}
}