[英]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.