我试图在Cognito + Node Js应用程序中自动确认我的用户。 我将此代码作为Util进行了尝试,并且在函数内部;不能使它工作
我尝试去看aws文档,但是代码模棱两可,解释不多。
这是我的代码:
course
有人可以帮我说,我做错了什么吗? 谢谢
答案 0 :(得分:1)
在注册回调中,您应该调用AdminConfirmSignUp。语法如下。
userPool.signUp(req.body.email, req.body.password, attributeList,
null, function (err, result) {
event = {
request: {
"userAttributes": {
"email": req.body.email
},
"validationData": {
"Name": "email",
"Value": req.body.email
}
},
response: {
autoVerifyEmail: true
}
}
// Confirm the user
var confirmParams = {
UserPoolId: 'provide your user pool id', /* required */
Username: req.body.email /* required */
};
cognitoidentityserviceprovider.adminConfirmSignUp(confirmParams, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
// Set the email as verified if it is in the request
if (event.request.userAttributes.hasOwnProperty("email")) {
event.response.autoVerifyEmail = 'true';
}
// Return to Amazon Cognito
callback(null, event);
if (err) {
console.log("Error aws: ", err.message);
// return;
}
cognitoUser = result.user;
console.log('user name is ' + cognitoUser.getUsername());
next();
// return;
});
});
}