首页 > 解决方案 > 如何在 completeNewPassword 上设置自定义属性?

问题描述

我有以下代码

Auth.completeNewPassword(
        user,
        this.profileForm.get('newPassword')?.value,
        {
          "phone_number": String(this.profileForm.get('phone')?.value),
          "given_name": this.profileForm.get('fName')?.value,
          "family_name": this.profileForm.get('lName')?.value,
          "locale": this.profileForm.get('language')?.value,
          "custom:role": "user" // Error when this line is added
        }
      )
      .then(data => console.log("Changed Password! -->", data))
      .catch(err => console.log("Password change failed: ", err));

它失败了custom:role,我收到以下错误:

`Input attributes include non-writable attributes for the client XXXX`

此外,在 Cognito 中,角色属性不会显示为必需属性。我该如何设置?

标签: angularaws-amplify

解决方案


好的,我之前的答案不正确,所以我为了后代删除了它。

显然,我们必须先设置自定义属性的读取和写入权限,然后才能使用 Amplify 设置它。

酷 - 我们在哪里有这个设置?不在Cognito 控制台的“属性”选项卡中。它一直隐藏在APP CLIENTS选项卡底部的一个名为Set attribute read and write permissions. 选中您的自定义属性的复选框,您就拥有了。

糟糕的用户体验,但至少我现在有了答案。

来源:https ://forums.aws.amazon.com/message.jspa?messageID=882666


推荐阅读