The problem is with the wix code that is executed in user.getEmail, even though I use await and async the Wix code doesn’t and returns before the find email completes.
So I’m using a complicated work-a-round that calls getEmail a few more times until the Wix code finishes getting the email (it usually only takes 2 tries) :
await user.getEmail()
.then( async (email) => {
let memberFound = “yes”;
}) // end then email - found
. catch(async (err, member) => {
let memberFound = “no”;
if (member === undefined) {
user = wixUsers.currentUser;
userId = user.id;
for ( var num = 1, len = 3; num <= len; num++) { // try to find email 3 times
await user.getEmail()
.then( async (email) => {
if (email !== undefined) {
memberFound = “yes”;
num = len + 1;
} //end if email is not undefined
}) // end then email loop in catch error
} // end loop
} // end if member undefined in catch error
if (memberFound === “no”) {
// could not find email address - go to access error page
wixLocation.to(“/access-error”);
return Promise.resolve();
} // end if member not found
}); // end catch error