Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services Amazon cognito identity js,getting callback.newPasswordRequired不是函数错误_Amazon Web Services_Amazon Cognito - Fatal编程技术网

Amazon web services Amazon cognito identity js,getting callback.newPasswordRequired不是函数错误

Amazon web services Amazon cognito identity js,getting callback.newPasswordRequired不是函数错误,amazon-web-services,amazon-cognito,Amazon Web Services,Amazon Cognito,Amazon cognito identity js,在尝试更改已验证用户的密码时出现“callback.newPasswordRequired不是函数”错误 const poolData = { UserPoolId: 'eu-central-1_XXXXXXX' ClientId: '2xxxxxxxxxxxxxxxxxxo', } const authenticationData = { Username: name, Password: oldPassword, } co

Amazon cognito identity js,在尝试更改已验证用户的密码时出现“callback.newPasswordRequired不是函数”错误

const poolData = {
  UserPoolId: 'eu-central-1_XXXXXXX'
  ClientId: '2xxxxxxxxxxxxxxxxxxo',
}
const authenticationData = {
  Username: name,
  Password: oldPassword,
}
const authenticationDetails = new AuthenticationDetails(authenticationData)
const userPool = new CognitoUserPool(poolData)
const cognitoUser = new CognitoUser({ Username: name, Pool: userPool })

cognitoUser.authenticateUser(authenticationDetails, {
  onSuccess(result) {
    cognitoUser.changePassword(oldPassword, newPassword, function (err, passwordChangeResult) {
      if (err) {
        console.warn(err.message || JSON.stringify(err))
      }
      console.warn(`Password change result: ${passwordChangeResult}`)
    })
  },
  onFailure(err) {
    console.warn(err)
  },
})
return null
}

Cognito似乎正在返回一个您尚未定义的newPasswordRequired回调。我假设您将用户创建为管理员,然后在登录时提示您重置密码

从这里[1]可以实现newPasswordRequired回调,如下所示

cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            // User authentication was successful
        },

        onFailure: function(err) {
            // User authentication was not successful
        },
 
        mfaRequired: function(codeDeliveryDetails) {
            // MFA is required to complete user authentication.
            // Get the code from user and call
            cognitoUser.sendMFACode(mfaCode, this)
        },
 
        newPasswordRequired: function(userAttributes, requiredAttributes) {
            // User was signed up by an admin and must provide new
            // password and required attributes, if any, to complete
            // authentication.
 
            // the api doesn't accept this field back
            delete userAttributes.email_verified;
 
            // store userAttributes on global variable
            sessionUserAttributes = userAttributes;
        }
    });
[1]