Logged in user and hidden elements.

Hello, I have a website and on the home screen I have a strip that says click here to sign up, etc. I want to hide/collapse the strip when the user logs in. I got the code and everything else and it works fine. The only problem is that if I go to another page of my website and then go back to the home page, the hidden/collapsed strip is back and you can see it. I’ve looked everywhere for different codes, can I have some help. The codes I’m using are

import wixUsers from 'wix-users';  
$w.onReady(() => {     
    wixUsers.onLogin( (user) => { 
        $w('#box18').show(); 
            $w('#box22').hide(); 
            $w('#box17').hide(); 
                $w('#box24').show(); 
                $w('#box21').show(); 
    }); 
});

I'm also using

$w("#myElement").collapse();

or

if( $w("#myElement").collapsed ) { 
  $w("#myElement").expand(); 
} 
else { 
  $w("#myElement").collapse(); 
}

The last other two codes, I’ve been putting in the middle of the first code seeing if I could change it up a bit. Thanks!

Hi wixlover,
You also want to check if the user is logged in.
(the formatting got lost in the copy/paste)

import wixUsers from 'wix-users';   
$w.onReady(() => {          
wixUsers.onLogin( (user) => { 
myFunction()
}); 
if (wixUsers.currentUser.loggedIn) {
myFunction()
}

}); 
function myFunction() { //set the name to what it does or something
$w('#box18').show(); 
$w('#box22').hide(); 
$w('#box17').hide(); 
$w('#box24').show(); 
$w('#box21').show();  
}
2 Likes

Hi wixlover (cool name)!

Simply use this bit of code in the site code instead of a specific page code.
All of the code that is used on components in the header/footer should be placed there.

Let me know if it solved your issue.

Doron. :slight_smile:

1 Like

Thank You! The only question I have is where it say myFunction, what do I rename it?

Thank You! I put the code the Ethan Snow gave me and it worked when I put it in the site code instead of page. The only problem is because I used collapse instead of hide, the other element at the bottom of the page shows a big gap because it moved up. How do I get rid of the gap?

@wixlover0 Is there a reason for you to use collapse instead of hide?
Because this is your solution right here :slight_smile:

@doron-alkalay The reason I’m collapsing the strip is because if I hide it then it leaves a big gap with nothing