Skip to content

Commit

Permalink
[BUGFIX] Fix identification for logged in frontend users
Browse files Browse the repository at this point in the history
Because TSFE->fe_user was dropped in TYPO3 13, FE user identification was not possible (without error).
See https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.0/Breaking-102605-TSFE-fe_userRemoved.html for details
  • Loading branch information
einpraegsam committed Dec 7, 2024
1 parent c2424bb commit 6acfcb3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions Classes/Utility/FrontendUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6acfcb3

Please sign in to comment.