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?
Update (12 Jan 2018):
The amazon-cognito-identity-js
devs have locked the aws-sdk
version in v1.31.0, so you don't have to downgrade aws-sdk
anymore, just upgrade the package:
npm install [email protected] --save
Looks like there's a problem with the aws-sdk
package. It's the dependency of the amazon-cognito-identity-js
package that you're using.
You could try to downgrade it by running:
npm install [email protected] --save
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With