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
if you want to refresh / reload a page look at wixLocation.to in the API Docs
You can use the wix-users.onLogin() function to refresh the screen.
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
To let the page reload, use:
wixLocation.to('wixLocation.url');
This will send the user to the current URL, so that it reloads.
If i used a button to perform this function (the button would be OnClick) what code would i write under the event handler to reload the current page?
Thanks
Adam
@adcatch02 I believe I made a mistake, just put this underneath the event handler:
wixLocation.to('wixLocation.url');
Without the extra .to.
J.D
August 16, 2019, 12:43pm
8
@webmasterq remove the quotation marks. It’s not a string.
@jonatandor35 Okay, but why? This works too.
J.D
August 16, 2019, 12:49pm
10
@webmasterq because wixLocation.url is a variable with a string assigned to, not a string by itself.
@jonatandor35 I know what you mean, but if it works, it works.
J.D
August 17, 2019, 6:07pm
12
@webmasterq but it doesn’t work…
aapgcup
October 15, 2020, 5:06pm
13
Where I have to put this for reload ?:
wixLocation.to('wixLocation.url');
J.D
October 15, 2020, 5:26pm
14
Please open a new thread and explain in more details when do you want to redirect.