Project

General

Profile

Actions

Bug #96137

closed

Aspect of frontend.user wont't work after Middleware 'typo3/cms-frontend/authentication'

Added by Dieter Porth almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-11-29
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

I registered an own middleware with.


    return [
        'frontend' => [
            'me/ext/fileload-for-user' => [
                'target' => \Me\Ext\Middleware\FileloadForFeUser::class,
                'before' => [
                    'typo3/cms-frontend/static-route-resolver'
                ],
                'after' => [
                    'typo3/cms-frontend/authentication'
                ]
            ],
        ],
    ];  

I could get the Id of my login-user but not its usergroups. I needed the workaround. I could not get the aspects.

        $context = GeneralUtility::makeInstance(Context::class);
        // Checking if a user is logged in
        $userUid = $context->getPropertyFromAspect('frontend.user', 'id');
        $userGroupsRaw =$genericRepository->findFieldLikeUsergroupInFeUsersByUid($userUid); // Simple request with QueryBuilder on fe_users
        if (is_string($userGroupsRaw)) {
            $userGroups = (($userUid !== false) ?
                array_merge(
                    [0,-2],
                    array_map(
                        'intval',
                        explode(',', $userGroupsRaw)
                    )
                ) :
                (false)
            );
        } else {
            $userGroups = false;
        }
//        $userGroupsRaw = $context->getPropertyFromAspect('frontend.user', 'groupIds');  // this wont work i only got [0,-2]

Actions #1

Updated by Benni Mack almost 3 years ago

  • Status changed from New to Closed

In TYPO3 v10 the usergroups have to be resolved at a later point (once TSFE->initUsergroup() is called), and thus relies on a lot of other logic.

So, your middleware needs to be placed at a later point.

In TYPO3 v11 (this was a breaking changes), groups are resolved at a much earlier stage, making it much easier.

Actions

Also available in: Atom PDF