Hey GOS,
I think that I have already done as you have suggested.
What I am saying is that after Login the function getfirstName is returning “undefined” not quite sure why. (note that I have this on site code NOT page code. I need to be able to leverage login/on ready from any page.
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
function getfirstName() {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then( (results) => {
return results.items[0].firstName;
} );
}
$w.onReady(function () {
if (wixUsers.currentUser.loggedIn) {
$w('#loginButton').label = `Logout ${getfirstName()}`;
// results in "Logout undefined" on the button label.
} else {
$w('#loginButton').label = `Partner Signon`;
}
});
wixUsers.onLogin(() => {
$w('#PartnerSharebtn').show();
// results in "Logout undefined" on the button label.
$w('#loginButton').label = `Logout ${getfirstName()}`;
});
export function loginButton_click(event) {
if ( $w('#loginButton').label === "Partner Signon" ) {
wixWindow.openLightbox("SignonLightbox");
} else {
wixUsers.logout();
wixLocation.to("/");
}
}