【问题标题】:Reactjs AWS Cognito - How to Handle newPasswordRequiredReactjs AWS Cognito - 如何处理 newPasswordRequired
【发布时间】:2018-11-16 15:16:40
【问题描述】:

我在反应应用程序中使用 AWS Cognito Javascript SDK。我有一个由管理员在 AWS 控制台中创建的用户。用户会收到一封电子邮件,其中包含他们的用户名和临时密码。现在根据我的理解,我必须通过 newPasswordRequired 流程,但是我已经为此苦苦挣扎了几个小时,现在尝试了多种不同的方法,但没有一个能让我到任何地方。当我检查 AWS 控制台时,用户池中的用户设置为 FORCE_CHANGE_PASSWORD。

这是我当前状态的代码。请如果有人可以帮助我解决这个过程,因为我对使用 Cognito 身份验证还很陌生。

function setNewPassword(data) {
  console.log("data \n", data)
  var authenticationData = {
    Username: data.username,
    Password: data.temp_password
  };
  var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(
    authenticationData
  );
  var userPool = new AmazonCognitoIdentity.CognitoUserPool(config.cognito);
  var userData = {
    Username: data.username,
    Pool: userPool
  };
  var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
  return new Promise(function(resolve, reject) {
    cognitoUser.authenticateUser(authenticationDetails, {
      onSuccess: function(result) {
        resolve(resolve);
      },
      onFailure: function(err) {
        reject(err);
      },
      newPasswordRequired: function(userAttributes, requiredAttributes) {
        this.cognitoUser.completeNewPasswordChallenge(newPassword, attributesData, this)
      }
    });
  });
}

在浏览器控制台中,我收到以下错误:

{code: "UnknownError", message: "Unkown error"}

【问题讨论】:

    标签: reactjs amazon-web-services amazon-cognito


    【解决方案1】:

    您是否曾在此处使用 AWS Amplify JS 库寻求帮助?已经构建了一套 React 组件来帮助处理这些事情。这是the relevant documentation 的链接。该代码已在 GitHub 上开源,您或许可以使用RequireNewPassword component,或者至少从中找到灵感。

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2017-09-27
      • 2018-02-23
      • 2020-10-17
      • 1970-01-01
      • 2016-02-24
      • 2017-06-24
      • 2016-05-19
      • 2021-04-15
      相关资源
      最近更新 更多