Member Login Issues

I’ve got member login issues that appear to be browser version or OS specific. A number of users can login when using Windows 10 + Chrome (v73), but other users on Mac OS 10.5 + Chrome or Windows 10 + Edge can’t. I’ve got the following code below, and interestingly when I log the wixUsers.currentUser immediately after login prompt it does have the correct user.id for that login. The issue appears to be with the user.getEmail() call which fails with an error indicating that “no user is currently logged in”.

wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
let message = "Current User: " + JSON.stringify(wixUsers.currentUser);
console.log(message);
if (user === undefined || user === null ){
console.log(“login attempt failed”);
}
else {
setupUser(user);
}
});
}
}

async function setupUser(user){
console.log(JSON.stringify(user));
await getUsersEmail(user);
}

async function getUsersEmail(user)
{
await user.getEmail().then( async (email) => {
let member = await wixData.query(“Artists”).eq(“email”, email).find();
console.log(member);
if (member.items.length === 0 || member.items.length > 1){
logoutUser();
}
else {
loginUser(member);
}
}). catch ((onRejected) => {
console.log(JSON.stringify(onRejected));
});
}

Wish I had better news Tom. This “feature” quit working for me a week or two ago. (It had been working fine and it just mysteriously stopped). Anyway…I just bit the bullet and wrote my own registration and login pages using a lightbox and API’s. My code was pretty much a duplicate of what you have here. Would love to hear if you are able to get this working as it should so I can just revert to out of the box functionality.

Thanks Jay,
I like your eventual solution, as it keeps you in control, and will probably have to adopt the same approach. Would be good though if Wix listed this as a known issue, given that there appears to be quite a few posts around this problem. Will certainly post a fix if I find one.

I’m having the same problem but only in mobil version. I get the same errors showed in the post. any Idea on how to solve this or if I could use the code showed above to fix this problem?

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