We’ve recently migrated wix-users and wix-users-backend APIs to the new wix-members and wix-members-backend namespaces. This change clarifies the terminology and puts these APIs where you would expect to find them.
We’ve also added some long-awaited new functions-
the profile system still has a bit of sluggish loading… do you intend to improve this?the profile system still has a bit of sluggish loading… do you intend to improve this?
I’m seem to run into a little bit of trouble with the new members. getMember functions in the backend. I can’t return the ‘FULL’ fieldsets when I call these functions from a backend event such as wixPaidPlans_onPlanPurchased . I can only get the public info and not the full info, for example to get a client’s e-mail address.
I wonder if you could give clarification on how to set/update custom fields with wix-members backend. There seems to be a difference in method between members . updateMember and authentication . register . In the documentation of ‘updateMember’ the custom fields parameters are an object, in ‘register’ they are not described as objects.
If you have any custom fields created on contacts - they will be displayed with the “+ Add” button near them. If there are no custom fields on contacts side - click on “+ Add Custom Field” and you’ll create a new custom fields
Thank you for your explanation @maksim-norkin . Can I run something by you to check if I’m using the members backend API in the right way?
I have a membership site with multiple ways for customers to get access to paid content:
They can buy a pricing plans
They can buy a customized product
I have made a backend validation script to check if a customer has access to the paid content when they go to certain pages. Non-paying customers can still access these pages, but they will get less content on them. For (1) I check the contact labels using wix-crm-backend. For (2) I wanted to use extended fields, also through wix-crm-backend. However I seem to get some issues when trying to set the extended fields.
When someone buys the custom product, I use
a) the backend authentication . register function if they are not a site member, to give them an account on the site.
b) the backend members . updateMember function if they are already a member
I was able to set the necessary extended field with (a) but not with (b) and the two seem to need a different syntax, which I didn’t fully figure out yet.
But now I’m also wondering if I’m actually going about this in the right way. You are mentioning that the extended fields in contacts are a platform for the custom fields in members. They need to be connected in the ‘customize info’ screen of the site members. The custom field will then appear in the member account screen, however I don’t really want customers to be able to set this field themselves, because they needs to purchase the product to get access.
Hey, so you need to use wix-crm-backend and set the custom field in there.
All the members are contacts as well - you’ll be able to control what they do with custom fields of contacts without connecting custom fields to members.
@maksim-norkin thank you for your guidance. I am still running into some trouble implementing the scenario where I register a customer as a site member programmatically. As you mentioned I set the custom field using wix-crm-backend. (the extended fields are contained in the ‘contactInfo’ parameter below).
import { authentication } from 'wix-members-backend';
import { contacts } from 'wix-crm-backend';
export async function registerUser(email, contactInfo) {
let password = "elkwjer434"
contactInfo.emails = [{ email }]
let resolvedContact = await contacts.appendOrCreateContact(contactInfo)
let userId = resolvedContact.contactId
let identityType = resolvedContact.identityType
let isMember = identityType !== "CONTACT"
if(isMember){
password = "***"
return { status: "already a member", email, identityType, userId, password}
}
return authentication.register(email, password)
.then((result) => {
console.log(result)
let userId = result.member._id
return { status: "successful", email, password, userId }
})
.catch((err) => {
console.log(err)
throw err.toString()
})
}
The result of this function is a duplicate contact with the same email - one a site member, and one a non-member. Only the non-member seems to have the extended fields that I want. When I delete the duplicate non-member, and try to run the function again, the member contact still doesn’t get updated with the extended fields.
yes I think you could still do that if you make your function asynchronious. For example
import {currentMember} from 'wix-members';
$w.onReady(async function () {
let member = await currentMember.getMember()
if(member){some code etc.}
if(!member){some other code}
})
if you want it to be more similar to the wixusers you could make it more compact
if(await currentMember.getMember()){some code etc.}
else{some other code}