I've wrote the following code to show a box if a user is logged in only. When the user log in you have to manually refresh the page to reflect the changes. how to I make this automatic? When user log out the changes it works properly.
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#box1").show();
}
else {
$w("#box1").hide();
}
} );
You can take a look here
Old thread. Closing it.
Where I have to put this for reload ?:
wixLocation.to('wixLocation.url');
To let the page reload, use:
wixLocation.to('wixLocation.url');
This will send the user to the current URL, so that it reloads.
Your page code should look something like this (quick and dirty example):
import wixUsers from 'wix-users'; import wixData from 'wix-data'; import wixLocation from 'wix-location'; $w.onReady( () => { setupPage(); wixUsers.onLogin( (user) => { setupPage(); } ); } ); export function setupPage() { if(wixUsers.currentUser.loggedIn) { $w("#box1").hide(); $w("#box2").show(); } else { $w("#box1").show(); $w("#box2").hide(); } }
I hope this helps.
Yisrael
You can use the wix-users.onLogin() function to refresh the screen.
if you want to refresh / reload a page look at wixLocation.to in the API Docs