Adding fields to private members data

HI,

Does anyone know hoe you can add fields to the private members data for example i want their weight in there.

If i cant add to the private members data set can you add a new collection and then reference the private members data some how?

I had a custom members page previously which was OK, but i do like the functionality off the wix pre made version for use in the forums and stuff how ever i find it a bit limited and not very flexible and wanted to see if i could make it more flexible some how.

Could someone share how this is done via code please?

Thanks

Fraser

Hi,

First of all, you won’t be able to add fields to the PrivateMemberData database.

For full list of permissions and possibilities on this collection, you may want to read this : https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields

You can try Reference Fields in your new database to reference PrivateMembersData’s fields in your new collection. (I am not sure which fields will be available). See here : https://support.wix.com/en/article/displaying-content-from-multiple-database-collections-using-reference-fields-4034931

Hope you will find those links usefull.

Bests

But you cant seem to reference any field in the Private Members Data collection the option has been greyed out.

I tried and I was able to create a reference field inside a new database, referencing the email field of the PrivateMembersData.

1/ Make sure you have one member in PrivateMembersData

2/ Go into your new database, and create a Reference Field (referencing Members/PrivateMembersData)

3/ Select which user you want to reference

This only works this way, (you won’t be able to create any fields into PrivateMembersData).

Hope this helps

HI Oscar

But in my new members area (My Diet Info) page i dont want to add email again to this input form that doesnt make any sense at all. In this My Diet Info page i want to add a few fields like weight and food dislikes and so on and have it only read write by the author.

Surely by adding it as a members page and then creating a new collection and linking a few manual inputs to a form it will submit the data to the collection and the ID will be the logged in user wont it? the issue is i cant even get the damn input boxes to allow read write if i set it to just write its fine but as its a members page i only want to show one set of data per member here not as like a form where you have mulitple submissions per user.

Basically i want to retain the usefulness of wix members because i want to add forums and so on. i dont want to manually set up a members area.

Feel free to see the test page here login and become a mmeber and go to My Diet Info
https://krays238.wixsite.com/mysite

All you need is a second DATABASE with a referenced field which will be connected to the USER-ID. The USER-ID will be needed because you have to know which user is logged in to find the right user-data in your additional DATABASE.

For example:

  1. You have made you own DATABASE with additional information about a user, with user-data like …

a) weight
b) height
c) eye-color
d) hair-color
…and so on…

Now you have also to implement the USER-ID-REFERENCE to this DATABASE.

Then, when everything is done and a user enters a page, you query for the current loggen-in user when page loads…

You can get almost all informations from the “PrivateMembersData” when you use this CODE here…

import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );
14
15user.getRoles()
16  .then( (roles) => {
17    let firstRole = roles[0];
18    let roleName = firstRole.name;                // "Role Name"
19    let roleDescription = firstRole.description;  // "Role Description"
20  } );
21
22user.getPricingPlans()
23  .then( (pricingPlans) => {
24    let firstPlan = pricingPlans[0];
25    let planName = firstPlan.name;          // "Gold"
26    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
27    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
28  } );

So right now you have found the right USER-ID, which will be needed to finf the right ADDITIONAL-USER-DATA of the CURRENT-LOGGED-IN-USER.

Then query your ADDITIONAL-DATABASE and filter for the founded USER-ID.

wixData.query("myCollection")
6  .find()
7  .then( (results) => {
8    if(results.items.length > 0) {
9      let firstItem = results.items[0]; //see item below
10    } else {
11      // handle case where no matching items found
12    }
13  } )
14  .catch( (err) => {
15    let errorMsg = err;
16  } );

ET VOILA ! ! ! ! YOu have what you were searching for!

Thanks but how do you reference the ID field because the main field in Private Members Data is locked to the Email field and you cant change it.

I created a field named ID as a reference column in my new collection “My Diet Info” but it shows the email not the ID

see below how do specifically reference ID and why do i need to if the Owner in the new My diet info is already the same id as the private member?

That’s why I was talking about using the email of the current logged in user instead of the ID.

You will be able to reference the email, and use the code russian-dima give you above

import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );

to identify which user is logged in, get his email, and use it to find the correct info in your new DB.

I am sure it is also possible without e-Mail, but try this first.
If it works for you, than also good job.

I know your question is about adding fields to the read-only private member database collection, but let me rewrite your problem a different way …

Goal:

Allow members to sign in, submit their own diet information to later view and/or edit their information each time they log in.

Proposed Solution:

Build the member a dashboard area so they can log in, click a button, submit a form, save, view and edit information using little to zero code.

Known:

As the other coders have already mentioned, you cannot edit data from the Private Members Database.

Yes, you can create a separate database and then filter by owner / or another reference point, such as an email address. (And this would work perfectly fine if someone other than the Owner is inserting data into the database)

CQ Recommedation:

Try this tutorial site: https://codequeen.wixsite.com/membership-dashboard
(You will find a link to the tutorial video on that site as well)

There are many ways to build a dashboard solution. The tutorial I linked above will show you one way of: creating a dashboard area for a member, checking to see if they have filled out a form, if no data exists them prompt them to add new data.

You can modify this flow, of course, depending if you want them to enter 1 record or multiple records.

If you want them to enter multiple records, it is as simple as creating a form and allowing them to submit the information. This way you could:

  • add a page to display their records (table or repeater)

  • add a dataset and connect to table or repeater

  • add dataset filter via dataset settings (Owner is logged in)

  • add a dynamic page to show / allow them to edit their record

  • add a button / link table row to the dynamic page

  • add ‘only author’ can view or edit their data via database permissions

  • no extra code for filtering required (zero code, all filtering is being done by dataset and database permissions)

I have helped hundreds of students & clients build custom dashboard solutions. It’s all a matter of getting the logic correct. Sometimes knowing the goal will help you find better answers to reach that goal.

Well done Nayeli, good explanation!

As i always say —> There are always several ways of solution given to solve a problem. :grin:

Thousands! Yet all we can do is propose solutions and hope they find one they understand. What is easy for 1 person, can be confusing for the other. The reason Forum’s like this work is exactly FOR that reason!

Lot’s of people can suggest different solutions, until the person finds the right combination that they understand best. It’s all about communities coming together.

Yes, i agree. Sometimes it’s me who is confused, although i am the helping person xD🤣 (Ok, Nayeli you are right now on your own, see ya😉)!

Thanks @code-queen , @russian-dima & @oscar-aveline let me give that a whirl tomorrow morning looks perfect! thanks so much for helping me out you guys are awesome. Love the ability to use the wix members app rather than creating your own members area saves alot of hassel

F

HI it works great thanks! one thing

Where does Wix collect the name from for the login name ? as mine still says Krays23 which is the first part of my email? How do i get it to say Dan?

in the site members panel the name is missing

Glad you got it to work out for you!

To answer your question, yes & no.

Yes, will collect the person’s name upon sign up ONLY if:

  • they signed up using a social media account (where the name can be pulled)

  • Wix detects the same email address from an existing Wix account (where the name can be pulled) <— this one is only a guess

  • If you code a custom registration window

Otherwise, no, because Wix does not ask for first or last name in the native registration window. So if the person signs up with only an email address — the name ‘does not get recorded’.

One last thing the data.js file has a couple of error trinagles and it doesnt check for duplicates in the sign up page works fine in the profile page but by then its too late the user has already duplicated the username.

1st error says res is already declared in the upper state

2nd says unreachable code

Can you let me know how i fix it?

Thanks

F

Do you need a username for your setup? If your profiles and such are private ---- you don’t really need a username.

The username function is just an example of creating 1 unique value, especially if it will be used for dynamic URL in the future.

To answer your questions, (by only viewing a part of your code) there could be extra spaces and by hitting the delete button it should remove those spaces. For the repeated variable — just change it to a different one. Like res1 or res2, etc. If you change it on your line 91, then you must also change it on your line 93.

Also, there should be an email address line in the code. It is the email address of the person who created the 2nd part of the code. You can try contacting them for any questions.

Hello again,

like the error-message already said…

res is already declared in the upper state
You surely have used this declaration 2x try to rename one of these…to…

a) result , or…
b) results, or …
c) RES, or …
d) RESULTS, …
or whatever!

Do it the way, so that you do not have ddeclarations with the same name in your code. This should resolve the problem.

The second problem exists, because you surely have placed the return-function onto the wrong place. You have to put it inside the function.

hi thanks i just copied it directly from code queens site so must be wrong there.

can you re arrange the code for me so i understand better please?

import wixData from ‘wix-data’ ;

export function searchForDuplicateUsernames(value) {

return wixData.query( “profile” )

    .eq( "username" , value.username) 

    .find() 

    .then((results) => { 

return results.items.length;

    }) 

    . **catch** ((err) => { 

let errorMsg = err;

    }) 

}

// emailAddress

export function searchForUsernamesIds(value) {

//This will check if the username and email is the same i.e, The username is not changed by the user

return wixData.query( “profile” )

    .eq( "username" , value.username) 

    .eq( "emailAddress"  , value.emailAddress) 

    .find() 

    .then((results) => { 

return results.items.length;

    }) 

    . **catch** ((err) => { 

let errorMsg = err;

    }) 

}

export function profile_beforeInsert(item, context) {

return searchForDuplicateUsernames(item, context).then((res) => {

if (res > 0 ) {

return Promise.reject( ‘This username is already taken’ );

    } 

return item;

}); 

}

export function profile_beforeUpdate(item, context, value) {

//courtesy of Salman from the Totally Codable Code community that helped finish this code

//fb.com/salman2301 or salmanhammed77@gmail.com preferred facebook

return searchForUsernamesIds(item, context).then((res) => {

if (res > 0 ) {

// the user name is not change but some other value is changed

return Promise.resolve( ‘Updated the changes’ );

    }  **else**  { 

// The username is changed , Checking if the username value is taken by some other member or not

return searchForDuplicateUsernames(item, context).then((res) => {

if (res > 0 ){

return Promise.reject( ‘This username is already taken’ );

            } 

    }) 

    } 

return item;

}); 

}

export function onUpDate(value) {

return wixData.query( “profile” )

    .eq( "username" , value.username) 

    .find() 

    .then((results) => { 

return results.items.length;

    }) 

    . **catch** ((err) => { 

let errorMsg = err;

    }) 

}