[英]util.crypto.lib. randomBytes is not a function : aws cognito js throws error on authentication
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): 更新(2018年1月12日):
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: amazon-cognito-identity-js
开发者在v1.31.0中锁定了aws-sdk
版本,所以你不必再降级aws-sdk
,只需升级包:
npm install amazon-cognito-identity-js@1.31.0 --save
Looks like there's a problem with the aws-sdk
package. 看起来aws-sdk
包有问题。 It's the dependency of the amazon-cognito-identity-js
package that you're using. 这是您正在使用的amazon-cognito-identity-js
包的依赖关系。
You could try to downgrade it by running: 您可以尝试通过运行降级它:
npm install aws-sdk@2.177.0 --save
Downgrading is the only option right now. 降级是目前唯一的选择。 I faced this error for hours, unable to figure out the actual issue. 我几个小时都遇到了这个错误,无法弄清楚实际问题。 I guess AWS should maintain proper versioning and push only stable versions. 我想AWS应该保持适当的版本控制并且只推送稳定版本。 :\\ aws-sdk 2.177.0 works just fine. :\\ aws-sdk 2.177.0工作正常。 You can use the angular-2-cognito boilerplate by AWS. 您可以使用AWS的angular-2-cognito样板。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.