Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error updating user attributes #238

Closed
vipseixas opened this issue Feb 6, 2018 · 16 comments
Closed

Error updating user attributes #238

vipseixas opened this issue Feb 6, 2018 · 16 comments
Labels
documentation Related to documentation feature requests

Comments

@vipseixas
Copy link
Contributor

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.

@vipseixas
Copy link
Contributor Author

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.

@mlabieniec mlabieniec added investigating This issue is being investigated documentation Related to documentation feature requests and removed investigating This issue is being investigated labels Feb 6, 2018
mlabieniec added a commit that referenced this issue Feb 6, 2018
mlabieniec added a commit that referenced this issue Feb 9, 2018
* update quickstart

* update docs index with examples

* Update index.md

* fix retrieve unauth credentials if not logged in, Fixes #229

* fix docs #238

* update details around react-native hocs

* update signUp api description

* updates based on review
@vincentsolutions
Copy link

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);

@navjotdhanawat
Copy link

How to update custom attribute @vipseixas ?

@Jasminou
Copy link

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

@j0b0sapi3n
Copy link

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?

@vipseixas
Copy link
Contributor Author

@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);

@j0b0sapi3n
Copy link

@vipseixas what's the point of doing currentCredentials in your example? You're not using it at all in updateUserAttributes()

Do you mind sharing the CognitoUser object that currentAuthenticatedUser() is returning? Is the Session value null?

@alexandprivate
Copy link

I am getting Session: null when calling var user = await Auth.currentAuthenticatedUser(); that;s the reason for the error on currentCredentials() ... any ideas ?

@vipseixas
Copy link
Contributor Author

@j0b0sapi3n There was a bug that prevented Auth.currentAuthenticatedUser() to fill the user credentias and that's why I used the Auth.currentCredentials() to force the credentials to be loaded inside the user object. I think that this is not the case anymore at newer versions.

@miljojohn
Copy link

miljojohn commented Aug 3, 2018

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..

@mevert
Copy link

mevert commented Aug 8, 2018

I just had similar issue and it turned out that I had old version 0.3.0. After updating aws-amplify to 1.0.5 "updateUserAttributes" started working again.

@NL33
Copy link

NL33 commented Nov 13, 2019

@vipseixas @mevert Can you share your current working code for updateUserAttributes?

I have tried various solutions offered here and it's not working yet.

@vipseixas
Copy link
Contributor Author

Hi @NL33, the code I used is in #238 (comment), but I haven't been working on this project for a long time and I don't know if something has changed.

@NL33
Copy link

NL33 commented Nov 14, 2019

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.

@jsnavarroc
Copy link

jsnavarroc commented Jul 7, 2020

I have the same problem I try this
image
But it doesn't work, and another thing is that if, for example, I access with a federated login, according to I read, neither can data be updated, for example, if I enter through Facebook, I cannot validate my phone number if it is not in Cognito. And how can it's in Cognito if no is possible update data from federation login?
image
image

@github-actions
Copy link

github-actions bot commented Jul 8, 2021

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Related to documentation feature requests
Projects
None yet
Development

No branches or pull requests