Amplify-js: Auth.currentUserInfo() not returning cognitoIdentityId

Created on 8 Feb 2018  路  14Comments  路  Source: aws-amplify/amplify-js

Since updating to "aws-amplify-react-native": "^0.2.2" running Auth.currentUserInfo() is not returning the cognitoIdentityId it just says id: undefined

{ id: undefined,
username: 'ivan2',
attributes:
{ email_verified: true,
phone_number_verified: false,
phone_number: '+555555555555',
email: '*********@gmail.com' } }

We are using this function to get the userInfo on login, then we store it to user storage, as suggested here https://github.com/aws/aws-amplify/issues/54#issuecomment-360958293

Is this still the correct function to get the cognitoId? What should we be using?


EDIT: I meant currentUserInfo _[ Sorry, I guess I shound't write issues at 2am 馃槅 ]_
Still, the function is returning id: undefined

Thanks!

investigating

Most helpful comment

still getting an undefined id here, amplify version is 0.2.11:

import { Auth } from 'aws-amplify';

const { id } = await Auth.currentUserInfo();   // id is undefined

All 14 comments

@Darkade There is currentUserInfo() method that returns user object with id

{
  id: 'us-east-1:500af417-2b3d-6da3-852b-ac1c5dc45dcd',
  username: 'testUser',
  attributes: {
    // ...
  }
}

Does it work for you?

@yuyokk I meant currentUserInfo [ Sorry, I guess I shound't write issues at 2am 馃槅 ]
Still, the function is returning id: undefined

@Darkade are you using:

import Amplify, { Auth } from 'aws-amplify';

This was a major release to remove duplication of code and core category logic into aws-amplify. So you should now import the Auth and Amplify category from aws-amplify, besides that all will be the same. aws-amplify-react-native only now contains HOCs / Components i.e. withAuthenticator or Authenticator.

@mlabieniec Yes this is my import line:

import Amplify, { Auth, Storage } from 'aws-amplify';

I find it weird because the rest of the object is returning fine. I can get the username and attributes just fine

Thanks

@Darkade can you try

"aws-amplify": "^0.2.4",

I just tested here with a fresh install and i do get the id when using the method:

let info = await Auth.currentUserInfo();
{
  "id": "us-east-1:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
  "username": "mlab",
  "attributes": {
    "email_verified": false,
    "phone_number_verified": true,
    "phone_number": "+xxxxxxxxxxx",
    "email": "[email protected]"
  }
}

@mlabieniec if I'm using the HOCs should I

"aws-amplify": "^0.2.4",
"aws-amplify-react-native": "^0.2.3",

?

@Darkade Yes that is correct (basically same as react web setup)

@mlabieniec I'm getting the same id: undefined

I don't know if this is related with us using the withAuthenticator HOC

Thanks

@Darkade I am using the HOC as well. Can you give a try:

watchman watch-del-all && rm -rf node_modules/ && npm cache clean && npm install && npm start -- --reset-cache

or similar with yarn etc.

And if you haven't already (if you are not using Expo 25+):

$ react-native link amazon-cognito-identity-js

import { Auth } from 'aws-amplify';

   async componentDidMount() {
        // get user
        let user = await Auth.currentAuthenticatedUser();
         console.log(user);

         // get jwt Token
         let jwtToken = Auth.currentSession().then(function(result) {
         console.log(result);
         });;
    }

This is what worked for me. Remove the part about jwt token if you do not need.

Also note that 'aws-amplify' and 'aws-amplify-react' are two different things.

This may be where your errors are coming from. Try importing auth from the other one

Hi @Darkade feel free to reopen if this issue continues.

Thanks

still getting an undefined id here, amplify version is 0.2.11:

import { Auth } from 'aws-amplify';

const { id } = await Auth.currentUserInfo();   // id is undefined

Auth.currentUserInfo() returns the identityId in the federated Identity Pool, so it is not the "sub" or id in user pool, so when you have "loged in" in your app, you have not this "id" because you need to get the credentials which have the identityId.

Had the same problem and in the Federated Identities settings under Authentication providers tab had the wrong App client id defined

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ddemoll picture ddemoll  路  3Comments

oste picture oste  路  3Comments

guanzo picture guanzo  路  3Comments

cgarvis picture cgarvis  路  3Comments

cosmosof picture cosmosof  路  3Comments