Amplify-js: Custom attributes not returned in Auth.currentUserInfo()

Created on 30 May 2018  路  18Comments  路  Source: aws-amplify/amplify-js

Do you want to request a feature or report a bug?

Not sure if this is a feature or a bug - according to https://aws.amazon.com/blogs/mobile/aws-amplify-adds-support-for-custom-attributes-in-amazon-cognito-user-pools/, it appears custom attributes should be retrievable (they use the example of a 'favorite_flavor')

What is the current behavior?

I have a Cognito user pool with limited standard attributes (email and email_verified). When I set a var to Auth.currentUserInfo(), I get the following back:

{id: "us-west-2:...ID...", username: "...USERNAME...", attributes: {email_verified: false, email: "[email protected]"}}

What is the expected behavior?

I expected to also see custom:roleType (a String) and custom:color (also a String)

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions?

0.4.1

Is this expected behavior?

Thanks for any help you can provide... I am hoping to use this custom attribute to affect what the user sees on the page. If I'm better off putting users into different User Pool Groups and segment that way, then a pointer to sample code for that would also be useful I suppose!

Thanks again.

Auth question

Most helpful comment

Setting attribute read and write permissions worked.

All 18 comments

Just tried this on v0.3.3 with the code:

Auth.currentUserInfo()
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.error(err);
      });

and got the result:

{
  "id": "us-west-2:41afa261-c02e-438c-82bc-05cc12586bdd",
  "username": "me-iamandrew.io",
  "attributes": {
    "email_verified": true,
    "phone_number_verified": true,
    "given_name": "Andrew",
    "custom:registration-step": "stripe",
    "phone_number": "+16232089405",
    "family_name": "Steinheiser",
    "custom:user_type": "provider",
    "email": "[email protected]"
  }
}

@chrisbnyc do you still have this problem?

Custom attributes need to be set readable or writable.

General Settings --> App clients --> Set attribute read and write permissions

==============================
INCORRECT

I have the same issue either by Auth.currentUserInfo() or Auth.userAttributes(user) - both don't return custom attributes.

Checked with Python boto3 as well - GetUser doesn't return custom attributes while AdminGetUser does. The former requires access token while pool id and username are necessary for the latter.

I wonder if GetUser is called instead of AdminGetUser.

@jaehyeon-kim can you leave that Set attribute read and write permissions as default and try again? I just found if you don't configure anything then it will return all the attributes you have.

@powerful23

I tried multiple amplify versions without checking custom attributes to be readable and they weren't returned.

Testing with Python is, with leaving custom attributes unchecked, they are not returned with GetUser. It is AdminGetUser that returns all attributes regardless.

@jaehyeon-kim can you try Auth.updateUserAttributes(user, attributes) to see if you could update those custom attributes?

Setting attribute read and write permissions worked.

I am using version 0.4.1 and I dont get custom attributes when I call Auth.currentUserInfo().
I have given read write permission as well as suggested here, although by default it should have read, write permissions.

Am I missing something here?

I am surprised, such a basic use case is a struggle.

@pachu4u can you try using the latest version of amplify? Also can you check the network request of the Auth.currentUserInfo() to see if there is any error message

@powerful23 - Tried with latest version 1.1.6, still do not see the custom attribute in response. All pre-defined attributes are present in the response.

@powerful23 - It is working. I was expecting the attribute to show up even when the value is empty. I did a new registration with the custom attribute and then I could see the custom attribute when I call Auth.currentUserInfo()

Thanks for your help

Closing the issue. Feel free to reopen if you still have this issue.

This issue should be left open until it is fixed. I need it to return an empty custom attribute field so we can enter the value in our app GUI. This should not be a problem for devs to solve with hacks. Same problem in the JS SDK so the only way so far I've found recommended is to use the CLI to enter data. That is a very poor hack. Please, someone on the team fix this. Also, trying to call custom:whatever in JS throws errors. "Custom" needs to go away. I tried setting up a var such as let something = custom:whatever and that doesn't work either.

@svstartuplab this is a behavior from the service side. We will escalate this to the Cognito service team.

This resolved case is an additional help on the original posted issue. issue:1084

For me, enabling aws.cognito.signin.user.admin option in App client settings did the trick.

I was struggling with this and it turns out the reason was not passing bypassCache: true after setting the attribute.

Auth.currentAuthenticatedUser({bypassCache: true})

That'll force the client to hit Cognito for the updated attributes which should include your custom attrs.

Here is the fix! Check out link.

Go to:
AWS Console > User Pool > General settings > App Clients > Show details > Set attribute read and write permissions (Click them all (check them all off)), Mark your custom attributes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ldgarcia picture ldgarcia  路  3Comments

DougWoodCDS picture DougWoodCDS  路  3Comments

rygo6 picture rygo6  路  3Comments

cosmosof picture cosmosof  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments