question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AWS SDK and Amazon Cognito Identity JS

See original GitHub issue

Describe the bug It seems the amazon-cognito-identity-js library and AWS SDK are inconsistent. Please correct me if I’m wrong.

What I’m trying to do is just use the cognito-identity-js library appropriately through the AWS-SDK as documented:

    var poolData = {
        UserPoolId : '...', // Your user pool id here
        ClientId : '...' // Your client id here
    };
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);

To Reproduce

const AWS = require('aws-sdk');
console.log(Object.keys(AWS)); //AmazonCognitoIdentity nor CognitoUserPool exist on this
const ci = AWS.CognitoIdentity
console.log(ci); //Nor on this
console.log(AWS.CognitoIdentityServiceProvider) //Nor on this.

Expected behavior Some way to access a user pool that is documented on the amazon-cognito-identity-js library.

Additional context I understand amplify is for client side apps. But most of us seem to have some need of cognito usage on the server side. It is taking tons of time to figure out.

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = ‘DEBUG’; in your app.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
stephenhuhcommented, Jan 25, 2019

@elorzafe @undefobj thank you for confirming this approach. though it slightly worries me that the SDK returns a UserAttributes object array of Value, Key object pairs instead of an object as it seems strange and non-deterministic.

It’s confusing to have it return an array and so I’ve even implemented a check:

CognitoAdaptee.prototype.getEmail = async function(uuid) {
  const promise = CognitoService.adminGetUser({
    UserPoolId: USER_POOL_ID,
    Username: uuid
  }).promise();

  return promise
    .then(({UserAttributes}) => {
      const EMAIL_INDEX = 4;
      const email = UserAttributes[EMAIL_INDEX].Value
      logger.info(`Got email of user from Cognito Service: ${email}`)
      return email;
    })
    .then(email => {
      if (typeof email !== string) {
        throw new Error('Critical Gateway Error: UserAttributes are non deterministic in ordering');
      }
      return email;
    })
    .catch(e => {
      logger.error(`Error from CognitoAdaptee: ${JSON.stringify(e)}`)
      throw e;
    })
}

Though I believe this may be a separate issue for another repo such as aws-sdk-js

Otherwise, thank you again for your help. I’ve closed this issue.

1reaction
elorzafecommented, Jan 24, 2019

@stephenhuh we create this RFC to see what features would you like to see in the future related to Auth Admin Tasks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cognito Identity Provider Client - AWS SDK for JavaScript v3
AWS SDK for JavaScript CognitoIdentityProvider Client for Node.js, Browser and React Native. Using the Amazon Cognito user pools API, you can create a...
Read more >
amazon-cognito-identity-js - npm
The Amazon Cognito Identity SDK for JavaScript allows JavaScript enabled applications to sign-up users, authenticate users, view, delete, and ...
Read more >
Amplify vs amazon-cognito-identity-js vs AWS SDK
amazon -cognito-identity-js # · Does it work in the backend? · When used on the frontend, it provides lower level (compared to Amplify)...
Read more >
amazon-cognito-identity-js - GitHub
No information is available for this page.
Read more >
Using Amazon Cognito Identity to authenticate users
// Import required AWS SDK clients and command for Node.js import {S3Client} from "@aws-sdk/client-s3"; import ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found