gpt4 book ai didi

javascript - 实用程序.crypto.lib。 randomBytes 不是函数 : aws cognito js throws error on authentication

转载 作者:数据小太阳 更新时间:2023-10-29 06:09:40 26 4
gpt4 key购买 nike

我收到以下错误:

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);
}
});

这可能是什么原因?我错过了什么?

enter image description here

最佳答案

更新(2018 年 1 月 12 日):

amazon-cognito-identity-js 开发人员已将 aws-sdk 版本锁定在 v1.31.0,因此您不必降级 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

关于javascript - 实用程序.crypto.lib。 randomBytes 不是函数 : aws cognito js throws error on authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48174252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com