I recently migrated all of my site code from the wix-users module to the new wix-members module. Everything seems to work fine, except for the following edge case:
When I first log into the site, the currentMember.getMember method will continue to error and either say “No User is Logged In” or returned undefined until I refresh my browser. Obviously this is not desired behavior, as I don’t want to have users refresh after every login event.
I have reverted back to the wix-users for now, but was wondering if anyone else is having this problem. Below is a test snippet on a non-priority page:
let x = await currentMember . getMember ()
let e = x . loginEmail
Error:
This error is showing, but I am logged in. Even if I leave the page and come back, it still returns undefined. I can visit the My Account page and see all of my details, but not access the currentMember programmatically. Once I refresh my browser, I am able to get the currentMember as expected.
I am using Gmail login, switching between different accounts to test.
@marlowe-shaeffer It was always an issue from the first time I migrated it (approx. 2-3 weeks ago). I had a TODO to look into why it was happening, but ran into some other issues before it could be addressed. But we’ve had multiple site users have a similar issue that seems to only happen in these circumstances. What I didn’t realize at first though was that it stays in this “broken” state until a hard refresh. I assumed it would only happen on the first page hit after login.
I’m encountering this issue as well. It seems to affect Wix events as well, as members only events are prompting logged in users to register.
EDIT:
I added this little snippet in masterPage.js as a workaround
import { currentMember } from 'wix-members';
import wixUsers from 'wix-users';
import wixLoc from 'wix-location';
$w.onReady(async function () {
const user = await wixUsers.currentUser
const id = await currentMember.getMember({fieldsets: [ 'FULL' ]})
.then((member) => {
return member.contactId;
})
.catch((error) => {
console.error(error);
return false
});
if(user.loggedIn && !id){
wixLoc.to(wixLoc.url.toString())
}
});
WixUsers.currentUser returns the correct status, but wixMembers doesn’t until a hard refresh. The code snippet hard refreshes the page if currentUser.loggedIn is true but getMember is undefined. Since it’s on masterPage.js the snippet basically runs on every page change
@russian-dima I don’t have a direct onLogin event handler. I am trying to access the member’s email on certain pages. Let’s say the user logs in and hits the homepage. I don’t need their info there, so nothing happening. Then the user navigates to page 2, where I try to pull their member email using currentMember.getMember() . This is returning undefined until a hard refresh. No matter how many pages the user visits, getMember() will continue to return undefined.
Not sure if I am supposed to do something in the onLogin to make it recognize the member is not undefined though.
let member = await currentMember.getMember();
let email = member.loginEmail
What does provide this code what is different to your one?
export async function getMemberData() {
let currentMember = await wixMembersBackend.currentMember;
//---------------------------------
let options = {fieldsets:['FULL']};
//---------------------------------
let member = await currentMember.getMember(options);
let email = await member.loginEmail;
let contactDetails = await member.contactDetails;
return({member:member, contactDetails:contactDetails, email:email});
}
@russian-dima This would be for backend code correct? I am trying to replace the deprecated wix-users module for my frontend code, not wix-users-backend.
When I do a hard refresh after login, everything works as you are describing. It’s simply running the code on a fresh login that causes things to fail.
@russian-dima It’s still broken. I copied your code exactly as you’ve listed it, and the issue is still present. If I login and navigate to my blank page, it returns undefined for “member”. Once I refresh, it works as you’re describing.
Just to add I’m currently experiencing issues with “wix-members” also, atm.
Both getMember and authentication.
Prompt login just doesn’t do a thing, no error nor lightbox. getMember is returning undefined.
Is this related to the issues with this and other modules that happened a week or 2 ago?
Regardless of whether it’s a bug or not, in my opinion, you should always refresh the page when users login or logout, just to make sure everything is okay.