Amplify-js: Updating mutable user attributes

Created on 22 Nov 2017  路  8Comments  路  Source: aws-amplify/amplify-js

Is there a way to update a way to update user attributes using this library?

Checked the documentation but doesn't mention anything about updating user attributes.

feature-request

Most helpful comment

@asharafshahi I think that's what you are looking for https://github.com/aws/aws-amplify/blob/master/docs/media/authentication_guide.md#user-attributes

UPD: I believe there is a typo in the docs

it says

let result = await Auth.updateUserAttributes({
    'email': '[email protected]',
    'last_name': 'Lastname'
});

but from the source I see that updateUserAttributes(user, attributes) requires user to be passed in as well

All 8 comments

We don't have this yet. In our backlog. We'll keep you posted.

@ChrisButterworth , I ran into this issue too and used something similar to this as a temporary work around.
```
import {
CognitoUserAttribute
} from 'amazon-cognito-identity-js';

const updateAttributesExample = (attributeName, attributeValue) => {
let user = getCurrentUser(dispatch);
user.getSession((err, session) => {
var disclaimerAttribute = [
new CognitoUserAttribute({
Name: attributeName,
Value: attributeValue
})
];

    user.updateAttributes(disclaimerAttribute, function (err, result) {
        if (err) {
            //handle the error
        }
        //do something with the success if needed
    });
});

}
````

Edit: formatting

Was this added recently? I'm also trying to update user attributes from my mobile react-native app. Thanks!

@asharafshahi it's in PR right now and should be in the next release!

If I'm using aws-amplify-react-native will the next release address this for me as well?

Thanks Amplify devs and @mlabieniec for getting the new release out! Looks like a lot of improvements. Sorry in advance if this should be obvious to me, but I looked through the docs to see what the new way to update user attributes is and I couldn't find it. A pointer would be much appreciated! thx

@asharafshahi I think that's what you are looking for https://github.com/aws/aws-amplify/blob/master/docs/media/authentication_guide.md#user-attributes

UPD: I believe there is a typo in the docs

it says

let result = await Auth.updateUserAttributes({
    'email': '[email protected]',
    'last_name': 'Lastname'
});

but from the source I see that updateUserAttributes(user, attributes) requires user to be passed in as well

You are right, the docs definitely have a typo. I tried the method as stated in the docs and it throws an error. When I call Auth.currentAuthenticatedUser and pass the result in as the first argument all goes well.

Was this page helpful?
0 / 5 - 0 ratings