当我尝试使用新密码设置经过身份验证的用户时,我收到以下 javascript 错误,但我无法弄清楚它发生在哪里。一旦我调用我的注册函数,用户实际上可以用一个新密码覆盖他们的临时密码,并且在 cognito 控制台中一切看起来都很好。他们还可以使用新密码登录。
Uncaught Error: n.onSuccess is not a function request.js?1405:31
at Response.eval (eval at <anonymous> (app.js:1290), <anonymous>:17:14072)
at Request.eval (eval at <anonymous> (app.js:1746), <anonymous>:355:18)
at Request.callListeners (eval at <anonymous> (app.js:1056), <anonymous>:105:20)
at Request.emit (eval at <anonymous> (app.js:1056), <anonymous>:77:10)
at Request.emit (eval at <anonymous> (app.js:1746), <anonymous>:668:14)
at Request.transition (eval at <anonymous> (app.js:1746), <anonymous>:22:10)
at AcceptorStateMachine.runTo (eval at <anonymous> (app.js:1884), <anonymous>:14:12)
at eval (eval at <anonymous> (app.js:1884), <anonymous>:26:10)
at Request.eval (eval at <anonymous> (app.js:1746), <anonymous>:38:9)
at Request.eval (eval at <anonymous> (app.js:1746), <anonymous>:670:12)
我的注册功能:
import {Config, CognitoIdentityCredentials} from 'aws-sdk'
import {CognitoUserPool, CognitoUser, AuthenticationDetails, CognitoUserAttribute} from 'amazon-cognito-identity-js'
import jwtDecode from 'jwt-decode'
import store from './store'
export default class CognitoAuth {
register (username, email, pass, newPassword, cb) {
let authenticationDetails = new AuthenticationDetails({
Username: username,
Password: pass
})
let cognitoUser = new CognitoUser({
Username: username,
Pool: this.userPool
})
cognitoUser.authenticateUser(authenticationDetails, {
newPasswordRequired: (userAttributes, requiredAttributes) => {
// the api doesn't accept this field back
delete userAttributes.email_verified
cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this)
}
})
}
}
注册.vue
signup () {
this.$cognitoAuth.register(this.username, this.email, this.oldPass, this.newPass, (err, result) => {
if (err) {
this.error = true
this.errMsg = err.message
console.error(err)
} else {
console.log('Login Successful:', result)
this.$router.replace(this.$route.query.redirect || '/search')
}
})
}