Member custom properties

Hi,

I’d like to create a custom member property that would store if user had opt-in or not to a beta test program. Is there a way to do this?
I can’t figure out how to store data by member with databases. For information, I am using the regular member area for simplicity.

Thank you,
Benjamin

Hi!
Members Area comes with Members Collection that stores all registered users (_id, email, firstName, lastName)
You can’t create and update data from Members Collection. Only read.
When would you like to receive this Custom Property from User?
1 If during registration, that I suggest you to use Custom Signup Form or Custom Corvid Form
Note: Collected information from Custom Signup will be stored in CRM Collection. You can get this info using method crm.getContactById(currentUser.id)
2 If after registration, that I suggest you to store information in you own User collection , that you can create and setup as you wish.

It would be after registration. I’d like them to be able to change a switch a button on the member area to opt-in. Then, if opted-in, the switch should be activated and user should be able to switch it off. Can you see what I need? It looks like a newsletter subscription checkbox.

Is there a way to synchronize the Members Collection with my own User collection as you mention ?

Thank for your help Illia,

@benp With Members Area you can’t add optional property and then change it on Members “My Account” Page
You can create your own “My Account” page with custom design and fields.
Users Collection will be store value of your Custom Property per User Email. It means, that you can get user email and query Users Collection to get Custom Property and do what you want.

When you need to write data with Custom Property to Users Collection?
It depends on you
So, I do:
When user go to “My Account” page I check for his email in Users Collection. If no data, then I create it with default data, it data exists I just use it and update if needed.
That’s all I can advise

@illiao Thanks for the help. I created the following code.
It works well on on computer but do not work on mobile, any ideas?

// For full API documentation, including code examples, visit Velo API Reference - Wix.com
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
var userEmail;
var aplusstatus;
var mbplusstatus;

$w.onReady(async function(){
var user = wixUsers.currentUser;
await user.getEmail()
.then( (email) => {
userEmail = email; // “user@something.com
});

await wixData.get("UserCustom", "benjamin@xxx.com") 
	.then( (results) => { 
		let item = results; //see item below 
		$w("#aplus").checked = item.aplus; 
		$w("#mbplus").checked = item.mbplus; 
	}) 

});

export function aplus_change(event) {
aplusstatus = $w(“#aplus”).checked;
mbplusstatus = $w(“#mbplus”).checked;
var toSaveA = {
“_id”: userEmail,
“aplus”: aplusstatus,
“mbplus” : mbplusstatus,
};
wixData.save(“UserCustom”, toSaveA)
}

export function mbplus_change(event) {
aplusstatus = $w(“#aplus”).checked;
mbplusstatus = $w(“#mbplus”).checked;
var toSaveMB = {
“_id”: userEmail,
“aplus”: aplusstatus,
“mbplus”: mbplusstatus,
};
wixData.save(“UserCustom”, toSaveMB)

}

I have no idea why it’s not working on mobile, but I see couple things in your code, that need to change. And then maybe it will work on mobile also.

  1. Use one of methods. You using Promise.then or you using async/await Promise . But not both like you now

  2. As I understand you must use wixData.get(“UserCustom”, userEmail) instead wixData.get(“UserCustom”, example@example.com”)

  3. I don’t recommend use async function as callback in $w.onReady().
    Best practice is to make async function main() and call it inside
    $w.onReady(function () { main() })

I am not a coder at all that’s why I was expecting bad practices to come up :slight_smile: Sorry if it hurts coder eyes !
Could you please tell me how to return the userEmail value and share the variable with the 2 other functions ? Without async/await, it returns “undefined” when I call the variable userEmail outside the getEmail function.

Thanks a lot for your help

(also could you please update your comment to remove my email from your post ?)

If you need a working code for your site, I can suggest you go to the Wix Arena