Reactjs React Cognito用户池-客户端试图写入未经授权的属性

Reactjs React Cognito用户池-客户端试图写入未经授权的属性,reactjs,amazon-cognito,aws-amplify,aws-userpools,Reactjs,Amazon Cognito,Aws Amplify,Aws Userpools,我正拼命想弄明白这件事。我的react应用程序中有以下代码。我需要为用户添加一些方法来添加单位/套数,因此我添加了一个自定义属性 一切正常,但当我包含apt\u number:this.state.unitNumber时,我得到错误{code:“NotAuthorizedException”,name:“NotAuthorizedException”,消息:“一个客户端试图写入未经授权的属性”} 我确实进入了我的设置,并使属性可写(我尝试使用Unit属性和apt number) 这是我的密码:

我正拼命想弄明白这件事。我的react应用程序中有以下代码。我需要为用户添加一些方法来添加单位/套数,因此我添加了一个自定义属性

一切正常,但当我包含
apt\u number:this.state.unitNumber时,
我得到错误
{code:“NotAuthorizedException”,name:“NotAuthorizedException”,消息:“一个客户端试图写入未经授权的属性”}

我确实进入了我的设置,并使属性可写(我尝试使用
Unit
属性和
apt number

这是我的密码:

const receivedNewUser = await Auth.signUp({
  username: this.state.email,
  password: this.state.password,
  attributes: {
    phone_number: this.state.phone,
    address: this.state.streetAddress,
    birthdate: this.state.dob,
    locale: this.state.zipCode,
    given_name: this.state.fname,
    family_name: this.state.lname,
    apt_number: this.state.unitNumber,
  },
});
发生了什么事


您需要添加
自定义:
作为属性名称的前缀

您的代码应为:

const receivedNewUser = await Auth.signUp({
  username: this.state.email,
  password: this.state.password,
  attributes: {
    phone_number: this.state.phone,
    address: this.state.streetAddress,
    birthdate: this.state.dob,
    locale: this.state.zipCode,
    given_name: this.state.fname,
    family_name: this.state.lname,
    'custom:apt_number': this.state.unitNumber,
  },
});