Skip to content

Commit

Permalink
[BUGFIX] Read frontend user instance from request where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Jan 26, 2025
1 parent c4a1348 commit 2411ce6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Classes/ViewHelpers/Security/AbstractSecurityViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use FluidTYPO3\Vhs\Utility\ContextUtility;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand Down Expand Up @@ -346,10 +347,20 @@ public function getCurrentFrontendUser(): ?FrontendUser
if (empty($GLOBALS['TSFE']->loginUser)) {
return null;
}
/** @var TypoScriptFrontendController $tsfe */
$tsfe = $GLOBALS['TSFE'];
/** @var FrontendUserAuthentication $frontendUserAuthentication */
$frontendUserAuthentication = $tsfe->fe_user;

$frontendUserAuthentication = null;
if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface) {
/** @var FrontendUserAuthentication|null $frontendUserAuthentication */
$frontendUserAuthentication = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.user');
}

if ($frontendUserAuthentication === null) {
/** @var TypoScriptFrontendController $tsfe */
$tsfe = $GLOBALS['TSFE'];
/** @var FrontendUserAuthentication $frontendUserAuthentication */
$frontendUserAuthentication = $tsfe->fe_user;
}

/** @var FrontendUser|null $frontendUser */
$frontendUser = $this->frontendUserRepository->findByUid($frontendUserAuthentication->user['uid'] ?? 0);
return $frontendUser;
Expand Down

0 comments on commit 2411ce6

Please sign in to comment.