[英]util.crypto.lib. randomBytes is not a function : aws cognito js throws error on authentication
我收到以下错误:
TypeError: __WEBPACK_IMPORTED_MODULE_0_aws_sdk_global__.util.crypto.lib.
randomBytes is not a function
当我尝试使用以下代码验证用户时,我写道:
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);
}
});
这可能是什么原因? 我错过了什么?
更新(2018年1月12日):
amazon-cognito-identity-js
开发者在v1.31.0中锁定了aws-sdk
版本,所以你不必再降级aws-sdk
,只需升级包:
npm install amazon-cognito-identity-js@1.31.0 --save
看起来aws-sdk
包有问题。 这是您正在使用的amazon-cognito-identity-js
包的依赖关系。
您可以尝试通过运行降级它:
npm install aws-sdk@2.177.0 --save
降级是目前唯一的选择。 我几个小时都遇到了这个错误,无法弄清楚实际问题。 我想AWS应该保持适当的版本控制并且只推送稳定版本。 :\\ aws-sdk 2.177.0工作正常。 您可以使用AWS的angular-2-cognito样板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.