Transfer data from wix members to my collection

Question:
So , I am making a website , wherein I have a Profiles collection , basically whenever the status of the member is changed from “PENDING” to “APPROVED” , I want a single profile to be added in the profiles collection for that specific member .
I tried to implement this using , wixMembers_OnMemberUpdated function , which
1)** runs multiple times**
2) and ends up adding multiple profiles for that specific member

To counter this , I tried adding an afterUpdate hook on the members collection , but it seems as if , when the status is MANUALLY changed to approved , after update hook is not executed.

Product:
Wix Editor, Wix Studio Editor

Are you able to share the code you’ve used?

Since wixMembers_OnMemberUpdated runs on every member change (e.g. they update their name from member settings), it’ll run every time. I imagine you likely don’t have a check in place to verify if they’re already in your custom collection or not.

Two solutions:

  1. Use an if - then statement inside the onMemberUpdated() event and run your code only if the status is set to APPROVED.
  2. Add the members inside your profile collection with the same _id as the member’s ID, or have a reference field linked to Members/PublicData collection. Before inserting an item inside your profiles collection, perform a query or get for the member’s ID and only add it if no previous records are found.