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.
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-
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.