【问题标题】:How to make user attributes from AWS userpool updateable?如何使 AWS 用户池中的用户属性可更新?
【发布时间】:2021-12-20 22:46:17
【问题描述】:

我正在尝试使用 AWS Amplify 更新来自 AWS Cognito 用户池的用户的属性。

try {
    const user = await Auth.currentAuthenticatedUser();
    await Auth.updateUserAttributes(user, {
        'nickname': 'newtestname'
    });
} catch (error) {
    console.log(error);
}

但我收到以下错误:

InvalidParameterException: user.nickname: Attribute cannot be updated.

我希望它是可更新的,因为我在我的 SAM 模板的 userpool-client 部分中使属性可写:

WriteAttributes:
        - email
        - nickname
UserPoolId: !Ref MyCognitoUserPool

这也正确反映在控制台中:

我没有应用程序客户端密码,并且启用了所有身份验证流程。安全配置设置为启用。 用户可以注册,所以我假设客户端中的 Amplify 配置没问题。

这里有什么问题?

【问题讨论】:

    标签: amazon-web-services amazon-cognito aws-amplify aws-userpools


    【解决方案1】:

    我发现了问题。在创建用户池时,我必须在架构定义中设置 mutable 标志,如下所示:

    Schema: 
      - Name: email
        Mutable: true
        ...
      - Name: nickname
        Mutable: true
        ...
    

    https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_CreateUserPool.html

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 2020-12-03
      • 2017-08-12
      • 2017-04-12
      • 2021-11-28
      • 2019-01-06
      • 2020-04-22
      • 2018-02-28
      • 1970-01-01
      相关资源
      最近更新 更多