Custom Field code

I already put coins as a custom field but it gives an error saying " Type ‘{ firstName: string; lastName: string; emails: string[]; labels: string[]; dealerRequest: string; }’ is not assignable to type ‘ContactInfo’. Object literal may only specify known properties, and ‘“dealerRequest”’ does not exist in type ‘ContactInfo’. It’s recommended you use a new variable, such as “let newVar = …” to make sure that all code completion work correctly."


import wixUsers from 'wix-users';

$w.onReady(function () {
    $w('#button1').onClick(function () {
        let email = $w('#input1').value;
        let password = $w('#input2').value;
        let coins = Number($w('#input3').value);
        
        wixUsers.register(email,password, {
          "contactInfo": {
            "coins": coins

          }})})})

Your code is missing the coins property on the contactInfo object.
It should be like this:

import wixUsers from 'wix-users'

$w.onReady(function () {
  $w('#button1').onClick(function () {
    let email = $w('#input1').value
    let password = $w('#input2').value
    let coins = Number($w('#input3').value)

    wixUsers.register(email, password, {
        contactInfo: {
          coins,
        },
      },
    })
  })
})

But I recommend that you migrate to the new Members API because the Users API is deprecated.

It will be something like this:

import { authentication } from 'wix-members'

$w.onReady(() => {
  $w('#button1').onClick(async () => {
    let email = $w('#input1').value
    let password = $w('#input2').value
    let coins = Number($w('#input3').value)
    //Create Options Object with contact info and custom fields
    let options = {
      contactInfo: {
        coins,
      },
    }

    try {
      const registrationResult = await authentication.register(
        email,
        password,
        options
      )
      console.log(registrationResult)
    } catch (error) {
      console.error(error)
    }
  })
})

It didn’t work. This time it sent this error " Type ‘{ coins: number; }’ is not assignable to type ‘string | number | Date’. Object literal may only specify known properties, and ‘coins’ does not exist in type ‘Date’. It’s recommended you use a new variable, such as “let newVar = …” to make sure that all code completion work correctly."

@metinazoz I’m really sorry, my code was not tested, I think it was an old implementation.

I edited for the correct one.

@bwprado This time I used the other code you sent but it didn’t work. It gave an error on options saying "A rgument of type ‘{ contactInfo: { coins: number; }; }’ is not assignable to parameter of type ‘RegistrationOptions’. Types of property ‘contactInfo’ are incompatible. Type ‘{ coins: number; }’ has no properties in common with type ‘ContactInfo’.

import { authentication } from 'wix-members'

$w.onReady(() => {
  $w('#button1').onClick(async () => {
    let email = $w('#input1').value
    let password = $w('#input2').value
    let coins = Number($w('#input3').value)
    //Create Options Object with contact info and custom fields
    let options = {
      contactInfo: {
        coins,
      },
    }

    try {
      const registrationResult = await authentication.register(
        email,
        password,
        options //it gave an error here
      )
      console.log(registrationResult)
    } catch (error) {
      console.error(error)
    }
  })
})

@metinazoz I don’t know what is wrong, although I only tested the code on the backend using this code:

import { authentication } from 'wix-members-backend'

export const createMember = async (email, password) => {
    let options = {
        contactInfo: {
            firstName: "Test",
            lastName: "Test",
            coins: 100,
        },
    }

    try {
        const registrationResult = await authentication.register(
            email,
            password,
            options
        )
        console.log(registrationResult)
    } catch (error) {
        console.error(error)
    }
}