Bug #90070

isLoggedIn not set in PSR-15 Middleware

Added by Thomas Kieslich about 2 months ago. Updated about 2 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Authentication
Target version:
-
Start date:
2020-01-08
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

/** @var UserAspect $frontendUserAspect */
        $frontendUserAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
        $id = $frontendUserAspect->get('id');
        $loggedIn = $GLOBALS['TSFE']->loginUser;
        $loggedInNew = $frontendUserAspect->isLoggedIn();

With this Code in a Middleware Script i get a ID (User is logged in) but no loggedIn Flag (false)
I found out that in the FrontendUserAuthentication Object the groupData Property is empty.
If i run GLOBALS['TSFE']->initUserGroups(); before, it works fine.
It should work without manual Initialization. This Code works fine:

        $GLOBALS['TSFE']->initUserGroups();
        /** @var UserAspect $frontendUserAspect */
        $frontendUserAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
        $id = $frontendUserAspect->get('id');
        $loggedIn = $GLOBALS['TSFE']->loginUser;
        $loggedInNew = $frontendUserAspect->isLoggedIn();

History

#1 Updated by Benni Mack about 2 months ago

  • Status changed from New to Needs Feedback

Unfortunately we had to keep the order of execution due to existing hooks during v9.x development the way it was before.

This means a frontend request does this in v9:
- Initialization of Site
- Initialization of TSFE
- Initialization of BE_USER
- Initialization of fe_user (based on the cookie)
- Evaluation of the page ID / Rootline
- TypoScript etc.

This does not make sense, as we can e.g. resolve a valid Frontend User earlier (which we've done properly in v10).

The context/aspect just gets updated as we go during that phase. For this reason, if you create a middleware and you need the manually call the initGroups() unfortunately (or actually TSFE->determineId) in v9.

#2 Updated by Thomas Kieslich about 2 months ago

Ok, thanks for the Hints. I think i can deal wit this fact and this Ticket can be closed.

#3 Updated by Riccardo De Contardi about 2 months ago

  • Status changed from Needs Feedback to Closed

@Thomas Kieslich thank you for your reply.

Closed in agreement with the reporter.

Also available in: Atom PDF