автоматическое подтверждение пользователей Cognito + Node JS - PullRequest
0 голосов
/ 07 ноября 2018

Я пытаюсь автоматически подтвердить своих пользователей в приложении cognito + node Js. Я попробовал этот код как Util, и здесь внутри функции; и не могу заставить его работать

Я пытаюсь перейти к документации aws, но код неоднозначен и мало что объясняет.

вот мой код:

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

  // 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;
});
}

Может кто-нибудь помочь мне сказать, что я делаю не так? спасибо

1 Ответ

0 голосов
/ 07 ноября 2018

в обратном вызове регистрации вы должны вызвать AdminConfirmSignUp. синтаксис приведен ниже.

https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_AdminConfirmSignUp.html

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;
          });

    });
 }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...