I'm trying to use the cognito user pool js sdk to create a user in cognito user pool. I was able to successfully do so on the front end by following this tutorial. However, I wanted to do it in the backend with node. I am trying to include the sdk like this
const AWSCognito = require('./amazon-cognito-identity.min.js');
const `AWSCognitoSDK` = require('./aws-cognito-sdk.min.js');
But node of the stuff I am using is defined. For example AWSCognito.config.region = 'us-east-1'; doesnt work because AWSCognito doesnt seem to have the attribute config.region. I tryed it with AWSCognitoSDK but that comes as an empty object when I log it to the console, so I wasn't really expecting that to work anyways. I tried using the solution in the below answer, but I couldn't get it to work
AWS Cognito unauthenticated login error (window is not defined) [JS]
I'd appreciate it if someone could help me in including the sdk and getting these lines to work in node
var poolData = {
UserPoolId : '...', // your user pool id here
ClientId : '...' // your app client id here
};
var userPool =
new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
Note: I also tried installing amazon-cognito-identity-js through npm but faced the same issues
---UPDATE---
I did the npm install based on Patrick's answer. Here is the errror I get
let userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool(poolData);
^
TypeError: Cannot read property 'CognitoUserPool' of undefined
at Object.<anonymous> (/Users/bbhakhrani/projects/nodekb/app.js:19:62)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Function.Module.runMain (module.js:701:10)
at startup (bootstrap_node.js:190:16)
at bootstrap_node.js:662:3
When I console.log this AWSCognito object, const AWSCognito = require('amazon-cognito-identity-js');, here are the properties that show
{ __esModule: true,
AuthenticationDetails: [Getter],
AuthenticationHelper: [Getter],
CognitoAccessToken: [Getter],
CognitoIdToken: [Getter],
CognitoRefreshToken: [Getter],
CognitoUser: [Getter],
CognitoUserAttribute: [Getter],
CognitoUserPool: [Getter],
CognitoUserSession: [Getter],
CookieStorage: [Getter],
DateHelper: [Getter] }