Yes that works brilliantly for you, however are you using the same as the code from the tutorial that David was asking about in the original post.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area
Yours is only setup to show or hide the login button and book buttons, it isn’t setup to change any button value after login is successful as per the tutorial code.
Plus, for all novice coders or non-coders that use that tutorial as a guide, it is much easier for them to follow the tutorial as it is set out and add their page refresh to their lightbox code instead.
Otherwise, it would mean them having to try and add the setupPage code correctly into their existing page code and have to sort out adding or removing any extra () or {}.
Plus, Wix would really need to look at revamping and changing that tutorial guide which shows the correct coding for if a logged in member is not directed to another page and simply stays on the same page after being logged in.
To be honest, I could perfectly well just go and add the code myself to my existing page code, of which I also used that tutorial as a basis for my own Members page, then simply take out the current page refresh in the login lightbox.
However, whilst everything is working fine and ticking over nicely, I’m not going to change anything until Wix decide to break something again when they release a new update!
Like a lot of things with code, there are also two ways of doing things and there is also one way that works for some and another way that works for others.
So happy that yours is working with Yisrael’s help, the wise old Wix man that he is:), must have come into his head during his lunch break with a nice cold beer!
Anyways, here is my code that I’ve used for the page code with the refresh being on my login lightbox and talking of cold beers, it is a nice warm sunny evening here and I’m off to enjoy a nice drink too!
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w("#loginbutton").label = "Logout";
$w("#membersareaonlystrip").expand();
$w("#whitegapforfooter").hide();
}
else {
$w("#loginbutton").label = "Login";
$w("#membersareaonlystrip").collapse();
$w("#whitegapforfooter ").show();
}
} );
export function loginbutton_onclick(event) {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#loginbutton").label = "Login";
$w("#membersareaonlystrip").collapse();
$w("#whitegapforfooter ").show();
} );
}
// user is logged out
else {
let userId;
let userEmail;
// prompt the user to log in
wixUsers.promptLogin( {"mode": "signup"} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query("Members")
.eq("_id", userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
"_id": userId,
"email": userEmail
};
// add the item to the collection
wixData.insert("Members", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#loginbutton").label = "Logout";
$w("#membersareaonlystrip").expand();
$w("#whitegapforfooter").hide();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function profilebutton_onclick(event) {
wixLocation.to(`/Members/${wixUsers.currentUser.id}`);
}
export function entermembersbutton_onclick(event) {
wixLocation.to(`/members-area`);
}
export function myaccountbutton_onclick(event) {
wixLocation.to(`/account/my-account`);
}
export function websiteupdatebutton_onclick(event) {
wixLocation.to(`/website-update`);
}