Synchronization issue with member creation using register()

Question:
I’m getting the following error around 50% of the time when trying to call the updateMember() Velo function after awaiting for register() to complete:

}
"jsonPayload":{
"message":"["message: 'Entity not found: Not Found'\ndetails:\n applicationError:\n description: Not Found\n code: NOT_FOUND\n data:\n notFound:\n entityId: 0af3ba36-886a-4eca-9599-2b1ce0d95474"]"
}
"receiveTimestamp":"2024-05-08T21:03:39.411Z"
}

I’m guessing this is due to a synchronization issue where the newly created member is not persisted to a database yet, even after register() has successfully returned the Id. I would like some advice on how to proceed.

Product:
I’m using Wix Editor with Velo APIs

What are you trying to achieve:
I’m trying to automate account creation for my site. I’ve created an endpoint on my site that does this by calling the register() and updateMember() Velo functions of wix-members-backend.

What have you already tried:
I’ve tried adding a delay of 1 second between the calls to register() and updateMember(), but the issue still occurs. I’ve also tried using the onMemberCreated() callback to do everything asynchronously, but the event doesn’t seem to be firing, even though it’s in the correct events.js file.

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

Can you share the two examples of the code that isn’t working? I assume you’re doing something like this?

const newMember = await authentication.register(email, password, options);
members.updateMember(newMember.member._id, memberInfo);

In preview mode or production? Backend events don’t fire in preview mode.

Yes that is basically what I’m doing:

var registrationResult = await wixMembersBackend.authentication.register(email, password);
console.log('after register: ' + registrationResult.member._id);
await delay(1000);
var updatedMember = await wixMembersBackend.members.updateMember(member._id, memberInfo);

the console log prints a valid id, which makes me think the member was already successfully persisted.

For the callback, my testing was in production, and my events.js file looks like this:

import wixMembersBackend from 'wix-members-backend';

export function wixMembers_onMemberCreated(event) {
  console.log("member created: " + event.member._id);
  wixMembersBackend.members.getMember(event.member._id).then(memberInfo => {
      ...
    })
    .catch(error => {
      console.error("Error fetching member:", error);
    });
}

None of the logs appear for this one

event.member._id does not exist within the event object

According to the API Reference

it is event.entity._id

I just tried changing the code to

export function wixMembers_onMemberCreated(event) {
  console.log("member created: " + event.entity._id);
  // wixMembersBackend.members.getMember(event.member._id).then(memberInfo => {
  //     console.log("Member fetched: ", memberInfo);
  //   })
  //   .catch(error => {
  //     console.error("Error fetching member:", error);
  //   });
}

And it still doesn’t show a log:

Are you attempting to use this function on the Preview site? If so, it wont work. Backend events only fire on the Published site. Aside from that, i need to know more about your issue or what you are trying to accomplish.

For this event not to fire, you would have to be running the site in preview mode, or the registration isnt processing successfully.

These definitely seem like two distinct bugs. I will raise these with the team internally but the best place to report this is customer care: Contact Wix

As for a workaround for the time being:

I realize the workarounds are not great but wanted to offer these as options in case you need this to work ASAP.

1 Like

This is on the live site (after clicking Publish, not Preview).

Thought I would leave this update here:

It seems like the callback runs correctly for accounts created independently of the automation using register(). 3 real user accounts were created today through regular form submission on our website.

So maybe register() doesn’t invoke onMemberCreated() after it’s done?

1 Like

Seems to be a possibility. Will check with our documentation team on this as well.

1 Like