Only display certain content for registered users?

I’m looking into using Wix for a website. On the site’s homepage I want to be able to display content for all users (registered or unregistered), and then display additional content once the user is registered and logged in (still on the homepage).

The page shouldn’t be hidden behind a “members only” wall or anything like that. I want it accessible to the public and registered users, but I want to limit the amount of content the unregistered users can see.

I looked into doing this with the provided APIs

import wixUsers from 'wix-users';

$w.onReady(function () {
 if(!wixUsers.currentUser.loggedIn){
        $w("#vectorImage1").hide(); // content hidden if you're not logged in
    } else {
        $w("#vectorImage1").show(); // content visible if you're logged in
    }
});

This technically works but it seems like all it’s doing is setting the element’s visibility to “hidden” which can be easily overridden in the dev console.

Is there a way to do this that doesn’t just “hide” the element using CSS, but actually removes it from the DOM, or is this beyond the scope of Wix Code?

Hi Mike,

As you mentioned, placing content inside the page means that it will be communicated to the visitor’s machine, regardless of it being hidden or visible.
And by modifying the relevant HTML properties in dev tools a more sophisticated user will be able to show any seemingly hidden content.

Therefore, the solution is to only send the data if the user is currently logged in.

Create a function that will check if a user is currently logged in and based on that retrieve the data from the backend resource such as a collection, and ‘attach’ it to the relevant page components.

Ah good point! That will work! Thanks for the quick reply