wixMember not working after initial login until refresh

Hello all!

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.

Any help is appreciated!

Hi @admin30811 When did this issue start? Was there a time after you migrated when it worked, and now it’s returning an error?

@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.

It seems another user is experiencing the same issue, so I’ve asked the team to look into it.

4 Likes

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

Thanks for sharing that! Hopefully there is a simple solution within the wix-members module so we can fully migrate over.

Where is your → onLogin-Code-part?
I do not see it in your code…

import { authentication } from 'wix-members';

authentication.onLogin((memberInfo) => {
  const memberId = memberInfo.id;
  console.log('Member logged in');
});

Please also take a look at…

@Rasyadi Abdoellah
You don’t need the DEPRICATED-WixUsers-API anymore at all!

@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.

@admin30811
You did NOT read this…

you would read it, you would understand your issue!

When you do everything the right way, you will get such an result…

What is missing in your code?

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});
}

Attention → Backend-Version!

@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.

@admin30811

Ok, perhaps it’s realy hard to understand … so here some more informations for you…

  1. Create a NEW-BLANK-PAGE in your editor.
  2. Paste this frontendcode into the code-section of the new generated page.
  3. Generate a button with the ID → “button1” on this new created page.
  4. Publish your website.
  5. Open your site/page in a browser of your choice.
  6. Make sure you are logged-out !
  7. Now log-in and take a look onto the CONSOLE!
  8. If nothing realy happened and you don’t see any console-logs …
  9. …press the created button, and take a look onto console again.
import wixMembers from 'wix-members';

$w.onReady(async()=>{
    start_MyLoginFunction()
    $w('#button1').onClick(()=>{start_MyLoginFunction();});
});

async function start_MyLoginFunction(){
    let currentMember = wixMembers.currentMember
    let member = await currentMember.getMember()
    let loginEmail = member.loginEmail
    console.log("Member-Data: ", member);
    console.log("login_Email: ", loginEmail);
}

So if you have done everything the right way → you should get something like…

As you can see → it also works on frontend.

  1. You got your e-mail now?
  2. You got your member-id now?
  3. You got your nickname now?
  4. You got your STATUS now?
  5. You got your PrivicyStatus now?
  6. and so on…

Compare your code and mine:

YOURS:

let x = await currentMember.getMember();
let e = x.loginEmail

MINE:

let currentMember = wixMembers.currentMember
let member = await currentMember.getMember()
let loginEmail = member.loginEmail

@admin30811 Just FYI, the team is still working on fixing this issue. Thanks for your patience.

@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.

2 Likes

@marlowe-shaeffer Thanks for the update.

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?

1 Like
You don't need the DEPRICATED-WixUsers-API anymore at all!

not true, it seems, we still need wix-users as wix-members is currently returning “undefined” and other methods within wix-members are failing too.

1 Like

@jay65866 I’m not sure. I asked the team and will get back to you once I have an answer.

1 Like

@marlowe-shaeffer : Did the problem is still active? Cause I am having it.

@youge Yes, as I mentioned in the other thread, the team is working on fixing this issue.

1 Like

Hi there,

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.