Display Header HTML to Logged-in Users Only

סיכום מבוסס בינה מלאכותית

The discussion revolves around displaying header HTML to only logged-in users on a Discourse forum. DigitalStartup and daxen initially seek a solution to show a banner or static HTML menu to registered users only.

daxen clarifies that a CSS solution, which hides the content from non-logged in users, is not sufficient as it can still be viewed in the page source or indexed by search engines. omarfilip suggests using a CSS solution, but daxen reiterates the need for a secure solution that doesn’t deliver the HTML block to non-logged in users.

DigitalStartup asks if a similar solution can be applied to hide HTML from certain Groups, but later clarifies that they meant Groups, not individuals. pmusaraj suggests using the “currentUser” or “api.getCurrentUser” method to determine whether a user is logged in.

daxen seeks a server-side solution, not a client-side (CSS/JS) solution, as they want to ensure that non-logged in users cannot access the HTML content. pmusaraj questions the need for a server-side solution, but daxen explains that a JS solution would not be secure as non-logged in users could access the JS file and view the HTML content meant only for logged-in users.

If I write a snippet of code in the Header (i.e. a banner or advertisement message), is there a way to wrap the code in something that ensures it only gets display to logged in users?

hi,

I’m looking for something similar.
i want to show a static html menu at the top, which should only be visible for registered users.

I would be interested in a solution too.

best regards,
Daniel.

Perhaps like this - wrap it in a div, i.e. logged_in_content and hide it from users who are not logged in:

html.anon div#logged_in_content {
  display: none;
}

as mentioned by @Falco:

I don’t want to hide it.
i want to deliver the html block to registered users only.

This will display it to those who are logged in and hide for those who are not.

yes, i know how css works :wink:

but this is no solution.

i dont want that not logged in users can see the html in page-source or it can be indexd by search engines.

its a closed forum and hiding with css is no solution.

i already tried this in the admin backend:
https://meta.discourse.org/t/adding-plugin-outlets-using-a-theme/32727/12

but without success.
the script tag an inner-html is not published.

Can something similar be done for hiding HTML from certain Groups? Or is a simple CSS solution too much to ask for this?

Edit: I misspoke. I didn’t mean individuals, just Groups. @pmusaraj @omarfilip

Search meta for either “currentUser” or “api.getCurrentUser” and you should see several code examples. You can use this to determine whether a user is loggedin, and then act accordingly.

Check if this method is still valid:

I’m not sure, but explore this topic:

this is a good solution, I have tested, but unfortunately not what I am looking for.

I’m looking for a server side solution, not a client side (css/js) solution.

Why do you have to have a server-side solution? Discourse is a full JS app, all of the header components for example have their html generated in JS. You can write the group-specific html in JS, and it will never be displayed to non-group users.

because my html content i want to show is only for logged-in users.

with this js solution every not logged in user can access the .js file over the url which is included always (in the login page too)

http_s://forum.domain.tld/theme-javascripts/83c1451748e441c882ef44430f033c57bb1ab1dd.js

and can see my js-injected html thats only for logged-in users.

i need a secure solution, not css/js pseudo secure solution.