0
votes

I'm using a Cognito userpool and Cognito federated identities to pass an IAM role to authenticated and unauthenticated users. When I try to switch a user from unauthenticated to authenticated, the developer console doesn't register that the change has happened; it is showing that I have 100% unauthenticated users.

Right now I instantiate my AWS client as an unauthenticated user and then call a function to update the credentials when they are available so I can switch them to authenticated. E.g.:

AWS.config.region = 'us-west-2';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
  IdentityPoolId: identityPoolId,
  region: 'us-west-2',
  Logins: {}
});

const updateCredentials = () => {
  const auth = store.getState().auth; //this gets the authentication credentials from a global store.
  AWS.config.credentials.Logins = {
    'cognito-idp.us-west-2.amazonaws.com/us-west-2_XXXXXXXXX': auth.idToken
  };
  AWS.config.credentials.expired = true;
};

As best as I can tell, this is the correct way to do this. See the documentation at the bottom of this page, and here, and here.

However, my console shows that I have no authenticated users, so updateCredentials is not switching users to authenticated. What can be done to fix this?

1

1 Answers

1
votes

at the end call AWS.config.credentials.get(()....)