AWS Amplify, await Auth.currentUserInfo

I need to get some custom attributes from Cognito, and to do something with that info.

I have this function:

const getMyAttribute = async (): string => {
  const userInfo = await Auth.currentUserInfo();
  console.log('userInfo', userInfo);
  return userInfo.attributes['custom:myAttribute']

And I’m calling it here in some React Component with:

const myAttribute = getMyAttribute();
console.log('myAttribute:', myAttribute); // Here is weird output
// Here I need to do something with `myAttribute`

In console.log I’m getting this:

myAttribute:  {"_40": 0, "_55": null, "_65": 0, "_72": null}

userInfo: {"attributes": {"custom:myAttribute": "6", "email": "", "sub": "etc..."}, ... rest of user info data from Cognito}

So, I’m getting some weird output in myAttribute at calling the function, but the real data from Cognito comes later on userInfo

How can I get the real data on myAttribute as well?

67 thoughts on “AWS Amplify, await Auth.currentUserInfo”

  1. 831013 819850Located your weblog and decided to have a study on it, not what I usually do, but this weblog is amazing. Awesome to see a web site thats not spammed, and in fact makes some sense. Anyway, wonderful write up. 148689


Leave a Comment