Startup behaviour using $:/status/UserName?

Hi

I’m using a multi-user node.js hosted TiddlyWiki setup behind a reverse proxy. Authenticated usernames appear correctly in the $:/status/UserName tiddler (recovered from the headers populated by the reverse proxy).

I want to customise the behaviour of tiddlers which are displayed on startup based on the logged in user. For example, to display a welcome message which can be dismissed by a user and which persists for their future sessions with the wiki.

Whilst I can construct the filter logic, I’ve found that at the point where the default tiddlers filterlist or when actions in tiddlers tagged with $:/tags/StartupAction/PostRender is evaluated the $:/status/UserName hasn’t been populated. Presumably this is because the TiddlyWeb adapter hasn’t updated the status yet from the server. If I run the same filter logic manually (e.g. triggered using a button) then it all works as expected.

I could write some Javascript which accesses the TiddlyWeb adapter method for updating status but with a different callback - but strikes me as overly complex.

Does anyone know a way of triggering a startup action after the server status tiddlers have been updated?
Alternatively, does anyone know a way of nicely delaying the evaluation of the startup actions? For example, triggering a sleep for a couple of seconds before evaluating a block of markdown?

Thanks

Paul

You can try using my TiddlyTools $action-timeout widget to add a timed delay to the actions performed by your tiddlers tagged with $:/tags/StartupAction/PostRender.

Just import https://tiddlytools.com/#TiddlyTools%2FTime%2Faction-timeout.js into your TiddlyWiki.

See https://tiddlytools.com/#TiddlyTools%2FTime%2FInfo for parameter usage.

For your particular use case, something like this would be go in your startup tiddlers:

\define myActions()
... your startup action widgets here ...
\end
<$action-timeout delay=1000 actions=<<myActions>> />

Note that you’ll probably want to experiment with the delay value (in milliseconds) to determine when the $:/status/UserName value has been properly populated.

enjoy,
-e

1 Like

That worked perfectly. Many thanks!
Paul

That solution might be a little flaky.

Eric’s plugin also supports setInterval. If I were you, I would use that method to poll for the username appearing (and then kill the timer). A far more robust solution than assuming 1000ms will always work on all networks/systems you might install it on.