0

I worked with older TYPO3 versions (< v9)

I am not able to fetch the logged in backend user in my frontend extension. In earlier TYPO3 versions I was able to do that.

Now when I logged in in TYPO3 backend and ask for it now it won't work anymore.

My approach is:

$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$be_username = $context->getPropertyFromAspect('backend.user', 'username');

I am getting an empty string. I know that backend user might be not available for FE. But I need to check on him.

Thank you for any suggestions.

1 Answer 1

0

If you want to find out if a Backend user is currently logged in, then the code is exactly right (you don't even need to check on the username).

$context = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Context\Context::class);
$isLoggedIn = $context->getPropertyFromAspect('backend.user', 'isLoggedIn');

However, if you do this in your extension in a Plugin, that is cacheable ("USER" cObject, or a "non-cacheable action" in an Extbase Plugin), this information could be cached, which can lead to serious! sideffects.

In general, you should only check for a backend user in Frontend-related events, PSR-15 middlewares or hooks from TSFE, not in plugins/cObjects etc. unless you really know what you are doing.

All the best, Benni-

Sign up to request clarification or add additional context in comments.

3 Comments

Well, I checked the code in TYPO3 version 9.5.9, Its return username for me. Don't know what's wrong with his case.
@Benni: Thanks, Can you give me a short example how to do that with hooks from TSFE?
@user3332010 are you using an Extbase plugin? Can you share your ext_localconf.php where you register your actions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.