Util.crypto.lib. randomBytes is not a function: aws cognito js causes authentication error

I get the following error:

TypeError: __WEBPACK_IMPORTED_MODULE_0_aws_sdk_global__.util.crypto.lib. randomBytes is not a function 

when I try to authenticate the user using the following code, I wrote:

 import { CognitoUserPool, CognitoUserAttribute, CognitoUser, AuthenticationDetails } from 'amazon-cognito-identity-js'; let authenticationDetails = new AuthenticationDetails({ Username: username, Password: password }); let userPool = new CognitoUserPool({ UserPoolId: 'us-east-1_1TXXXXXXbXX', ClientId: '4da8hrXXXXXXXXXXXXmj1' }); let cognitoUser = new CognitoUser({ Username: username, Pool: userPool }); // THE ERROR IS THROWN AS SOON AS IT HITS THE BELOW // STATEMENT cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function (result) { console.log('access token + ' + result.getAccessToken().getJwtToken()); }, onFailure: function(err) { console.log(err); } }); 

What could be the reason for this? What am I missing?

enter image description here

+5
source share
2 answers

Update (January 12, 2018):

The developers of amazon-cognito-identity-js blocked the aws-sdk version in v1.31.0, so you no longer need to aws-sdk , just update the package:

 npm install amazon-cognito-identity-js@1.31.0 --save 

There seems to be a problem with the aws-sdk package. This is the dependency of the amazon-cognito-identity-js package that you are using.

You can try to lower it by doing:

npm install aws-sdk@2.177.0 --save

+5
source

Currently, the only option is to downgrade. I encountered this error for several hours, unable to figure out the real problem. I think AWS should support proper versioning and click only stable versions .: \ aws-sdk 2.177.0 works just fine. You can use the angular -2-cognito pattern with AWS.

0
source

Source: https://habr.com/ru/post/1274586/


All Articles