繁体   English   中英

如何使 AWS 用户池中的用户属性可更新?

[英]How to make user attributes from AWS userpool updateable?

我正在尝试使用 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配置没问题。

这里有什么问题?

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM