Отправка электронной почты, когда пользователь создан в firestore с использованием облачных функций - PullRequest
0 голосов
/ 30 марта 2019

Я пытаюсь отправить ссылку для проверки электронной почты после того, как пользователь создан в моем приложении, но письмо не отправлено, и в моем журнале облачных функций я получаю сообщение при развертывании:

{"@ type": "type.googleapis.com/google.cloud.audit.AuditLog","status":ndom"code":9,"message":"FAILED_PRECONDITION" coming,"authenticationInfo": { "principalEmail": "*************"}, "requestMetadata": { "CallerIP": "186.216.140.62", "callerSuppliedUserAgent": "FirebaseCLI / 6.5.0, GZIP(GFE), GZIP (GFE) " "requestAttributes": { "время": "2019-03-29T23: 21: 10.130Z", "авт": {}}, "destinationAttributes": {}}," ServiceName":" cloudfunctions.googleapis.com», "имяМетода": "google.cloud.functions.v1.CloudFunctionsService.UpdateFunction", "authorizationInfo": [{ "разрешение": "cloudfunctions.functions.update", "получил":правда, "resourceAttributes": {}}, { "ресурс": "проекты / pppppp-9800a / локации / нас-central1 / функция / sendVerificationEmail", "разрешения": "cloudfunctions.functions.update", "предоставивший": Истинная, "resourceAttributes": {}}], "гesourceName ":" проекты / pppppp-9800a / местоположение / нас-central1 / функция / sendVerificationEmail " "запрос": { "@ тип": "type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest","функция ": {" метка ": {" развертывание-инструмент ":" кли-firebase "}," EventTrigger ": {" типСобытие ":" поставщики / cloud.firestore / eventTypes / document.create " "ресурс":"projects / pppppp-9800a / database / (по умолчанию) / documents / users / {userId} "," service ":" firestore.googleapis.com "}," sourceUploadUrl ":" https://storage.googleapis.com/gcf-upload-us-central1-dc1829cf-3a07-4951-be81-1a15f892ed8d/8ea3f162-c860-4846-9064-04a855efca2f.zip?GoogleAccessId=service-73683634264@gcf-admin-robot.iam.gserviceaccount.com&Expires=1553903464&Signature=******************","name":"projects/pppppp-9800a/locations/us-central1/functions/sendVerificationEmail"}}}

Мой код:

exports.sendVerificationEmail = functions.firestore.document('users/{userId}').onCreate((snap, context) => {
  const user = snap.data();
  console.log("----------------------");
  console.log("user created: " + user.uidColumn);
  admin.auth().generateEmailVerificationLink(user.email).then((link) => {
    console.log("**********" + link);
    sendVerificationEmail(user.emailColumn, link);
    return 0;
  }).catch(e => {
    console.log(e);
  })
  return 0;
});

function sendVerificationEmail(email, link) {
  var smtpConfig = {
    host: 'smtp.gmail.com',
    port: 465,
    secure: true, // use SSL
    auth: {
      user: 'myappemail@gmail.com',
      pass: 'password'
    }
  };

  var transporter = nodemailer.createTransport(smtpConfig);

  var mailOptions = {
    from: "qeaapp@gmail.com", // sender address
    to: email, // list of receivers
    subject: "Email verification", // Subject line
    text: "Email verification, press here to verify your email: " + link,
    html: "<b>Hello there,<br> click <a href=" + link + "> here to verify</a></b>" // html body
  };

  transporter.sendMail(mailOptions, function (error, response) {

    if (error) {
      console.log(error);
    } else {
      console.log("Message sent: " + response.message);
    }
    return 0;
  });
  return 0;
}

Когда я получаю команду firebase deploy Я получаю сообщение Функции: не удалось обновить функцию sendVerificationEmail Ошибка HTTP: 400, Изменение типа триггера функции или поставщика событий непозволено

Я новичок в JS, и я не знаю, что означают эти ошибки

1 Ответ

0 голосов
/ 30 марта 2019

Удалите вашу первую функцию с именем sendVerificationEmail, затем повторно разверните. Похоже, вы, возможно, изначально развернули его как нечто иное, чем триггер Firestore.

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