Joey Bouten
Joey Bouten

Reputation: 155

TYPO3 v10 - Getting feUser Object using context API in eID_include

Code that i used and need to update for V10

    $this->feUser = EidUtility::initFeUser();

When using the following code (a random) controller, the context gives me the correct login feUser object.

    $context = GeneralUtility::makeInstance(Context::class);
    $user = $context->getAspect('frontend.user');
    DebuggerUtility::var_dump($user);

When using the same code in an eID_include class No userObject is given.

Specificly in the following class

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['FileDumpEID.php']['checkFileAccess']['xxx'] = My\Class\Hooks\FileDumpHook:class

Is there a need of bootstrapping context?

Upvotes: 4

Views: 2463

Answers (2)

Sebastian Fischer
Sebastian Fischer

Reputation: 187

Since the TYPO3\CMS\Frontend\Middleware\EidHandler middleware is executed before the TYPO3\CMS\Frontend\Middleware\FrontendUserAuthenticator middleware in the middleware's order, I don't think that this is possible.

If you need parts of the frontend handling you either can add an own middleware with a dependency of TYPO3\CMS\Frontend\Middleware\FrontendUserAuthenticator or use a page Object in TypoScript.

Upvotes: 2

R. v. Rickenbach
R. v. Rickenbach

Reputation: 64

I had the same problem. You may change the order of Middlewares: https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/RequestHandling/Index.html

I've created a new file RequestMiddlewares.php inside the "Configuration" directory of my extension:

<?php

return [
    'frontend' => [
        'typo3/cms-frontend/eid' => [
            'disabled' => true
        ],
        'typo3/cms-frontend/eid-new' => [
            'target' => \TYPO3\CMS\Frontend\Middleware\EidHandler::class,
            'after' => [
                'typo3/cms-frontend/tsfe',
            ],
            'before' => [
                'typo3/cms-frontend/prepare-tsfe-rendering',
            ]
        ]
    ]
];

You have to flush TYPO3 and PHP Cache and check the ordering in "Configuration" backend module (select "HTTP Middlewares (PSR-15)").

With this setup it is possible to get the context property 'frontent.user'

$context = GeneralUtility::makeInstance(Context::class);

if($context->getPropertyFromAspect('frontend.user', 'isLoggedIn')) {

Upvotes: 2

Related Questions