I have this little snippet for logging in a user with my own Typo3 extension:
$GLOBALS['TSFE']->fe_user->createUserSession(array());
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->getRawUserByUid($this->userRepository->findByUsername($winAcc)->toArray()[0]->getUid());
$GLOBALS['TSFE']->fe_user->fetchGroupData();
$GLOBALS['TSFE']->loginUser = 1;
In the fluid template I can check if a user is logged in with this:
<f:security.ifAuthenticated>
This is being shown whenever a FE user is logged in
</f:security.ifAuthenticated>
However this code works only for the next action which is executed in the controller. When the FrontEnd User reloads the page, the authentication is lost and also $GLOBALS["TSFE"]->loginUser is null.
Why is this happening?