Addin Function After Sign Up

I am currently encountering an issue with inserting the member ID into another data collection once the user signed up through a reference field. Specifically, I have attempted to use the afterGet hook based on the PrivateMembersData collection, but it appears to be ineffective.

Upon further experimentation, I added the same code to an onClick button and found that it worked successfully. However, I am still unable to determine the source of the error in the initial implementation.
I would greatly appreciate any assistance you can provide in identifying where the mistake may lie.

Thank you for your time and support.

import wixData from 'wix-data';

export function Members$PrivateMembersData_afterGet(item, context) {
    const memberId = item._id;
    wixData.insert("AvailableForWork", { member: memberId })
        .then(() => {
            console.log("Member ID inserted successfully");
        })
        .catch((err) => {
            console.log(err);
        });
}

First you meant afterInsret (if I got you right). But I don’t think this hook will work on this specific collection.
Instead, use onMemberCreated( ) in the backend/events.js file. See:
https://www.wix.com/velo/reference/wix-members-backend/events/onmembercreated

Also, if every unique system member must have no more than one record in the AvailableForWork collection, I suggest to use the system member._id as the _id in the second collection as well (this way you can guaranty the system will not let you insert a certain user twice by accident) . Something like:

//backend/events.js
import wixData from "wix-data";
export function wixMembers_onMemberCreated(event) {
return wixData.insert("AvailableForWork", {
_id: event.entity._id, member: event.entity._id)
 }).catch(err => {
 if(err.errorCode === "WDE0074"){
 return Promise.resolve("User_already_exists");
 }
 })
}

Thank you so much
It will be great if you can explain to me how to create custom private page for the members out Wix Members App

I don’t think I got your question. Please elaborate,

Apologies for any confusion caused. To enable customization of member areas, I have created separate public and private member collections. However, these collections are still linked to the default member collection “PrivateMembersData” through a reference field.
Currently, the issue I am facing pertains to changing the user profile slug across all Wix Apps. Specifically, the profile button on the Wix Forum App is linked to the previous profile page URL (/profile/{user name}/profile), which cannot be edited through the editor interface.
Thus, I am seeking guidance on how to modify the member profile slug across all Wix Apps.

the above code is working perfectly with _id filed, but it doesn’t work with the fields generated by the system such as slug, nickname

Andy advises?

Hi,
add (to the object you insert):
slug: event.entity.profile.slug,
nickname: event.entity.profile.nickname

Here is the full event.entity info:

{
     "loginEmail": "john@example.com",
     "privacyStatus": "PUBLIC",
     "_id": "583b58eb-708e-4eba-bb8d-af7f9914721b",
     "_createdDate": "2021-12-10T10:44:37.000Z",
     "_updatedDate": "2021-12-10T10:44:36.939Z",
     "activityStatus": "ACTIVE",
     "profile": {
       "profilePhoto": {
         "_id": "a27d24_0dd318%7Emv2.jpg",
         "url": "http://static.wixstatic.com/media/a27d24_0dd318%7Emv2.jpg",
         "height": 0,
         "width": 0
       },
       "slug": "john40355",
       "coverPhoto": {
         "_id": "",
         "url": "https://example.com/myimage.jpg",
         "height": 0,
         "width": 0
       },
       "title": "Awesome title",
       "nickname": "John Doe"
     },
     "status": "APPROVED",
     "contactId": "583b58eb-708e-4eba-bb8d-af7f9914721b",
     "contactDetails": {
       "customFields": {
         "custom.pet-name": {
           "name": "Pet Name",
           "value": "Bob"
         }
       },
       "company": "Wix",
       "phones": [],
       "lastName": "Doe",
       "firstName": "John",
       "birthdate": "2000-01-01",
       "jobTitle": "Developer",
       "emails": [
         "john@example.com"
       ],
       "addresses": [
         {
           "city": "Jewell",
           "addressLine": "10 Cedarstone Drive",
           "_id": "156e50e8-8127-4617-a052-da66bb9a96a0",
           "country": "US",
           "postalCode": "43530",
           "subdivision": "US-OH"
         }
       ]
     }

I used the below code but the slug not inserted to ‘PublicMembersData’ collection, please advise

import wixData from 'wix-data';

export function wixMembers_onMemberCreated(event) {
    return wixData.insert("PublicMembersData", {
        _id: event.entity._id,
        memberReference: event.entity._id,
        _owner: event.entity._id,
        filter: event.entity._id,
        slug: event.entity.profile.slug,
        nickname:  event.entity.profile.nickname,
    })
    .catch(err => {
        if(err.errorCode === "WDE0074") {
            return Promise.resolve("User_already_exists");
        }
    })
}

That’s not the way to update the PrivateMembersData collection. It’s only work with your own custom collection.
To update the system collection, use:
https://www.wix.com/velo/reference/wix-members-backend/members/updatemember

" PublicMembersData" are custom collection, the other one called Members/PublicData

Please clarify