I have a page for site members only but I need to have their first and last names in addition to the required email address. Below is the code (snippet), in blue, to verify they are logged in and retrieve this information. It works as expected if the site member has already entered a first and last name in their profile but if those columns are null, it will not redirect them to the account page. Will someone please help me figure this out?
Thank you in advance!
/*****************************************************************************
/* Execute the code */
$w.onReady(() => {
//Get the userInfo...
let user = wixUsers.currentUser;
console.log("user = ",user);
userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
userEmail = email; // "user@something.com",
console.log(userEmail);
} );
//Get their login info to store in cart
if (isLoggedIn) {
//Get the users name
console.log("Query Members");
wixData.query("Members/PrivateMembersData")
.eq("_id", userId)
.find()
.then((results) => {
let items = results.items;
console.log("Members.results.items", items);
firstName = items[0].firstName;
lastName = items[0].lastName;
console.log("firstName = ",firstName); //yep, I see it
console.log("lastName = ",lastName); //yep, I see it
//If we know their first name, continue...
if(items.firstName !== null) {
console.log("found name: " + firstName);
$w("#columnStrip1").expand();
$w("#txtDisplayName").value = firstName;
}
//else, redirect them to the member account page to complete..
else
{
console.log("firstName is null");
$w("#columnStrip1").collapse(); //do not show the strip
wixLocation.to("/account/my-account"); //send them to set up
} // end the if firstName not null
}) // close query/then
...
} //end ifLoggedIn
}); //close onReady