Best way to check if you are guest in hook
-
I have this hook and I want to change the behavior when no one is logged in. Problem is that i do not have the req data for the current user. (Uid)
filter:parse.post
Any advice how to modify my post data when viewing in the forum.
-
The result of that hook is cached between users, which is why we don't provide any request data.
You may want to try
filter:post.get
instead. -
Thanks, I will do
result = await plugins.hooks.fire('filter:post.get', { post: postData, uid: data.uid });
I hope data.uid is the user that is active in the frontend.
Do you know if this also works for lazy load of posts. (when it loads more posts when scrolling in the thread?
Or does post.get hook only work for the first thing that loads?
Or do I need to modify multiple hooks postData.
-
I have a setting that should say. Only when guest else modify urls in postData both on logged in user and guest. Which is default.
-
The plugin modifies external weblinks. And that must work when loading more posts in a thread when scrolling.
-
-
Good catch I don't know why that hook is in the create function. You probably actually want
filter:post.getPosts
This one should should handle all posts regardless of how they load or what position they're in. It may however not handle post summaries so you might want to double check those.
-
Thanks, filter:post.getPosts works fine and has uid for the logged in user.
Did use filter:post.getPostSummaryByPids for summary.
And filter:teasers.get for teasers. All have uid