简体   繁体   中英

How to make user attributes from AWS userpool updateable?

I am trying to update attributes from users from a AWS Cognito userpool with AWS Amplify.

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

But I get the following error:

InvalidParameterException: user.nickname: Attribute cannot be updated.

I would expect it to be updateable because I made the attributes writable in the userpool-client section in my SAM template:

WriteAttributes:
        - email
        - nickname
UserPoolId: !Ref MyCognitoUserPool

This is also reflected correctly in the console: 在此处输入图片说明

I have no app client secret and all auth flows enabled. The security configuration is set to enabled. Users can register, so I assume that the Amplify config in the client is alright.

What is wrong here?

I found the issue. On creation of the userpool I had to set the mutable flag within the schema definition, like so:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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