ID Undefined in Auth.currentUserInfo() aws-sdk function

Asked

Viewed 36 times

0

Hello I am using the sdk of aws, to recover the information of the logged in user I am calling the method:

Auth.currentUserInfo();

But he returns the object:

attributes: {
    sub: "13fd444d-2b2c-4d5c-b8b5-022fd599fd11", email_verified: true, 
    phone_number_verified: false, phone_number: "+5599999999999", 
    preferred_username: "email"
},
id: undefined,
username: "456e972da800ba06e8a22bc8a9910d4e"

Notice that it returns id: undefined

Why does that happen? I’m working with the version: "aws-amplify": "^1.1.18"

link to documentation here

error that appears when enabling AWS debug

inserir a descrição da imagem aqui

1 answer

0

I managed to enter the code:

await (await Auth.currentCredentials()).getPromise();

before calling the Auth.currentUserInfo method():

async componentDidMount() {
    await (await Auth.currentCredentials()).getPromise();

    const info = await Auth.currentUserInfo()
    console.log('info: ', info)
    this.setState({ info })
  }

For context, the library tries to read the identityId of the credentials, but they may not be ready by calling Auth.currentUserInfo()

  • Cool! that gives me a bigger north, but when implementing in my code, it generated this error: Uncaught (in Promise) Typeerror: _a. sent(...). getPromise is not a Function

  • you tried the: async componentDidMount() {
 const user = await Auth.currentAuthenticatedUser()
 console.log('user info:', user.signInUserSession.idToken.payload)
 console.log('username:', user.username)
}

  • tested, it works and returns me information, but when I use await Auth.currentUserInfo(); it returns the objt with everything filled except the id as Undefined. PS: on my friend’s MAC works the same code and returns an id, on the windowns I tested back Undefined

Browser other questions tagged

You are not signed in. Login or sign up in order to post.