util.crypto.lib。 randomBytes不是一个函数:aws cognito js抛出身份验证错误 [英] util.crypto.lib. randomBytes is not a function : aws cognito js throws error on authentication

查看:67
本文介绍了util.crypto.lib。 randomBytes不是一个函数:aws cognito js抛出身份验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误:

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?

推荐答案

更新(2018年1月12日):

amazon-cognito-identity-js 开发人员已锁定v1.31.0中的 aws-sdk 版本,因此您不必降级 aws-sdk ,只需升级软件包即可:

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 amazon-cognito-identity-js@1.31.0 --save






看起来好像有问题 aws-sdk 软件包。这是您使用的 amazon-cognito-identity-js 包的依赖项。


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 aws-sdk@2.177.0 --save

这篇关于util.crypto.lib。 randomBytes不是一个函数:aws cognito js抛出身份验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆