当我尝试使用新密码设置经过身份验证的用户时,我收到以下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)
}
})
}
}
Register.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')
}
})
}
答案 0 :(得分:3)
您错过了onSuccess
回调实现,该实现在新会话成功时调用。见CognitoUser.js中的第341行。
例如:
.
.
.
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: (result) => {
// User authentication was successful.
},
onFailure: (err) => {
// User authentication was not successful.
},
mfaRequired: (codeDeliveryDetails) => {
// MFA is required to complete user authentication.
// Get the code from user and call:
cognitoUser.sendMFACode(mfaCode, this)
},
newPasswordRequired: (userAttributes, requiredAttributes) => {
// the api doesn't accept this field back
delete userAttributes.email_verified;
cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this);
}
})
.
.
.