【问题标题】:React Cognito User Pool - A client attempted to write unauthorized attributeReact Cognito 用户池 - 客户端试图写入未经授权的属性
【发布时间】:2019-04-27 18:22:26
【问题描述】:

我正用头撞墙,试图弄清楚这一点。我的反应应用程序中有以下代码。我需要为用户添加一些方法来添加单位/apt 编号,所以我添加了一个自定义属性。

一切正常,但是当我包含apt_number: this.state.unitNumber, 时,我收到错误{code: "NotAuthorizedException", name: "NotAuthorizedException", message: "A client attempted to write unauthorized attribute"}

我确实进入了我的设置并使属性可写(我尝试了 Unitapt 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,
  },
});

发生了什么事?

【问题讨论】:

    标签: reactjs amazon-cognito aws-amplify aws-userpools


    【解决方案1】:

    您需要将custom: 添加为属性名称的前缀。

    您的代码应为:

    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,
      },
    });
    

    【讨论】:

      猜你喜欢
      • 2017-10-16
      • 2017-07-06
      • 2018-12-18
      • 2019-10-15
      • 2020-06-04
      • 2018-11-19
      • 2020-01-11
      • 2013-08-03
      • 2015-02-01
      相关资源
      最近更新 更多