gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 13:43:48 26 4
gpt4 key购买 nike

我正在把头撞在墙上,试图弄清楚这个问题。我的 react 应用程序中有下面的代码。我需要添加某种方式让用户添加单元/公寓号,因此我添加了一个自定义属性。

一切正常,但是当我包含 apt_number: this.state.unitNumber, 时,我收到错误 {code: "NotAuthorizedException", name: "NotAuthorizedException", message: "A client试图写入未经授权的属性”}

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

这是怎么回事?

enter image description here

最佳答案

您需要添加 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,
},
});

关于reactjs - React Cognito 用户池 - 客户端尝试写入未经授权的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53475478/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com