3

The task is pretty simple: I want to display the full name (first- and lastname) of the current TYPO3 frontend user in Fluid. But somehow, TYPO3 (version 9.5) or Fluid seems to cache data, so a logged in frontend user sometimes sees the name of other another logged user.

Current implementation:

TypoScript:

lib.username = USER_INT
lib.username.userFunc = Vendor\Extension\UserFunc\Username->getUsername

This is a USER_INT, so the output should always be uncached.

Fluid Layout - Default.html:

<f:render partial="Header" section="Top" />

Fluid Partial - Header.html:

<f:section name="Top">
  <img src="logo.png">
  <f:render partial="Navigation" />
</f:section>

Fluid Partial - Navigation.html

<f:security.ifAuthenticated>
  <f:then>
    <p>Logged in as: <f:cObject typoscriptObjectPath="lib.username" /></p>
  </f:then>
  <f:else>
    <p>Not logged in</p>
  <f:else>
</f:security.ifAuthenticated>

Why does the result of the cObject get cached? Should'nt this always be calculated per request, because lib.username is a USER_INT? I also tried to add a f:cache.disable ViewHelper to the template with no success.

In order to resolve the problem I refactored it to fetch the full name of the fe_user using a JavaScript XHR request to a simple PSR-15 middleware. Is this really the only suitable solution or am I missing something?


Update 17.12.2020

This all works fine. I just spotted a typo in my userFunc, which resulted in the unexpected behavior.

derhansen
  • 5,585
  • 1
  • 19
  • 29

3 Answers3

0

This happens because TYPO3 cache works with frontend user groups, not frontend users. So you will see results cached for the list of user's groups rather than the current user.

Use <v:render.uncache> ... </v:render.uncache> from EXT:vhs to render that part of code uncached. Alternatively you can modify TYPO3 caching to use the current user but this may decrease cache performance and seriously increase amount of cached items.

User366
  • 765
  • 4
  • 9
0

Beware, that there is a caching problem even with USER_INT and COA_Int see https://forge.typo3.org/issues/37988

You could use only TypoScript for that like:

lib.username = COA_INT
lib.username {
  10 = TEXT
  10.data = TSFE:fe_user|user|first_name
  10.wrap = |&nbsp;

  20 = TEXT
  20.data = TSFE:fe_user|user|lastname_name
}
0

Why use TypoScript? It is very limited on what it can bring back. I just finished a tutorial where you can use a ViewHelper to add an ExtBase variable which assigns the whole user object in the FrontEnd and you can use it wherever you want with all it's relations, even the image, which is difficult to get via TypoScript.

TYPO3 tutorial

Best regards

share edit delete flag

Aristeidis Karavas
  • 1,891
  • 10
  • 29
  • Nice tutorial but also has the cache problem. All other users will see the name of the user who accessed the page first – fishbone Oct 18 '22 at 12:32
  • i know, but i might create a new one which handles the issue with Ajax and Middlewares – Aristeidis Karavas Oct 20 '22 at 08:42
  • 1
    It works now for me after I installed the vhs extension, put the `` and `{loggedInUser.firstName}` in a separate partial and included that partial with ``. Note that you have to put ` – fishbone Oct 20 '22 at 10:24