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.
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.
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);
How to update custom attribute @vipseixas ?
@navjotdhanawat I had the same issues with the 0.3.4, installing the latest version fix the problem for me
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 @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);
@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
?
I am getting Session: null when calling var user = await Auth.currentAuthenticatedUser(); that;s the reason for the error on currentCredentials() ... any ideas ?
@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.
Session: null
鈥媋ttributes: Object { "custom:document_id": "xx", "custom:dept_id": "xxx", "custom:institution_id": "xxxx"}
鈥媋uthenticationFlowType: "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 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.
@vipseixas @mevert Can you share your current working code for updateUserAttributes?
I have tried various solutions offered here and it's not working yet.
Hi @NL33, the code I used is in https://github.com/aws-amplify/amplify-js/issues/238#issuecomment-392550976, but I haven't been working on this project for a long time and I don't know if something has changed.
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.
I have the same problem I try this
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?
Most helpful comment
@navjotdhanawat @j0b0sapi3n
Sorry for the late response... I'm using this code with Amplify 0.3.3: