amplify-js: Error updating user attributes

I am following the docs:

let profile = await Auth.currentUserInfo();
let result = await Auth.updateUserAttributes(profile, {
    'foo': 'bar'
});

And getting this error: TypeError: user.getSession is not a function. Indeed the object returned from Auth.currentUserInfo() does not have a getSession() function.

I am using aws-amplify version 0.2.2.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (4 by maintainers)

Commits related to this issue

Most upvoted comments

@navjotdhanawat @j0b0sapi3n

Sorry for the late response… I’m using this code with Amplify 0.3.3:

let user = await Auth.currentAuthenticatedUser();
await Auth.currentCredentials();  // See https://github.com/aws/aws-amplify/issues/592
let params = {};
params['custom:' + name] = value;
let result = await Auth.updateUserAttributes(user, params);

Inspecting the source I found that the correct code might by:

let user = await Auth.currentAuthenticatedUser();
let result = await Auth.updateUserAttributes(user, {
    'foo': 'bar'
});

It seems that just the docs need an update.

Thanks, @vipseixas. My biggest issue has been finding the right documentation. After a lot of searching, I still have not found an actual code example from AWS on the right way to update user attributes. This link has some guidance, but not an actual example.

Session: null ​attributes: Object { “custom:document_id”: “xx”, “custom:dept_id”: “xxx”, “custom:institution_id”: “xxxx”} ​authenticationFlowType: “USER_SRP_AUTH”

TypeError: user.getSession is not a function

It seems to be because the Session value in the CognitoUser object that is returned from currentAuthenticatedUser() is null

Please help me to fix this…

I’m currently getting the error

user.getSession is not a function

after trying userAttributes() on my current authenticated user like so:

const currentAuthenticatedUser = Auth.currentAuthenticatedUser()
      .then(data => {
        console.log("currentAuthenticatedUser: ", data);
        const attributes = Auth.userAttributes(currentAuthenticatedUser)
          .then(data => {
            console.log("follow up attributes: ", data);
          })
      });

It seems to be because the Session value in the CognitoUser object that is returned from currentAuthenticatedUser() is null. I’m also on the latest (0.4.1) but I did try earlier versions and it didn’t seem to fix it. Any ideas?

@navjotdhanawat I had the same issues with the 0.3.4, installing the latest version fix the problem for me

By inspecting the source, I realized something and wanted to to point it out in case others would need it.

Currently, the docs says that you can retrieve userAttributes like this:

let user = await Auth.currentAuthenticatedUser();

But this doesn’t return the User Attributes directly. You then need to make another call like this:

let user = await Auth.currentAuthenticatedUser();
let userAttributes = await Auth.userAttributes(user);