diff --git a/Classes/Domain/Tracker/FrontenduserAuthenticationTracker.php b/Classes/Domain/Tracker/FrontenduserAuthenticationTracker.php index 748c0be5..9c91e900 100644 --- a/Classes/Domain/Tracker/FrontenduserAuthenticationTracker.php +++ b/Classes/Domain/Tracker/FrontenduserAuthenticationTracker.php @@ -28,7 +28,7 @@ public function trackByFrontenduserAuthentication(): void if (FrontendUtility::isLoggedInFrontendUser()) { $userRepository = GeneralUtility::makeInstance(FrontendUserRepository::class); /** @var FrontendUser $user */ - $user = $userRepository->findByUid((int)FrontendUtility::getPropertyFromLoggedInFrontendUser('uid')); + $user = $userRepository->findByUid((int)FrontendUtility::getPropertyFromLoggedInFrontendUser()); $this->setRelationToFrontendUser($user); $this->addEmailAttribute($user); diff --git a/Classes/Utility/FrontendUtility.php b/Classes/Utility/FrontendUtility.php index 2094a3e6..e313b0ea 100644 --- a/Classes/Utility/FrontendUtility.php +++ b/Classes/Utility/FrontendUtility.php @@ -5,6 +5,7 @@ use In2code\Lux\Domain\Service\SiteService; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication; use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; class FrontendUtility @@ -43,18 +44,27 @@ public static function getCurrentHostAndDomain(): string public static function isLoggedInFrontendUser(): bool { - return !empty(self::getTyposcriptFrontendController()->fe_user->user['uid']); + $authentication = self::getFrontendUserAuthentication(); + if ($authentication !== null) { + return $authentication->user['uid'] > 0; + } + return false; } public static function getPropertyFromLoggedInFrontendUser($propertyName = 'uid'): string { - $tsfe = self::getTyposcriptFrontendController(); - if (!empty($tsfe->fe_user->user[$propertyName])) { - return (string)$tsfe->fe_user->user[$propertyName]; + $authentication = self::getFrontendUserAuthentication(); + if ($authentication !== null) { + return (string)($authentication->user[$propertyName] ?? ''); } return ''; } + protected static function getFrontendUserAuthentication(): ?FrontendUserAuthentication + { + return $GLOBALS['TYPO3_REQUEST']?->getAttribute('frontend.user'); + } + /** * @return ?TypoScriptFrontendController * @SuppressWarnings(PHPMD.Superglobals)