首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取callback.newPasswordRequired不是函数错误

获取callback.newPasswordRequired不是函数错误
EN

Stack Overflow用户
提问于 2020-10-02 21:20:44
回答 1查看 1.2K关注 0票数 0

Amazon-cognito identity-js,尝试更改已验证用户的密码时出现"callback.newPasswordRequired is not a function“错误

代码语言:javascript
复制
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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-10-03 05:19:42

看起来Cognito返回了一个您还没有定义的newPasswordRequired回调。我假设用户是由Admin API调用创建的,而不是通过注册调用创建的。然后,在登录时,系统会提示您重置密码。

从这里1开始,您可以像这样实现newPasswordRequired回调。

代码语言:javascript
复制
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] https://www.npmjs.com/package/amazon-cognito-identity-js

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64172287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档