0

I'm trying to send the email verification link after the user is created on my flutter app, but the email isn't sent and in my Cloud Functions Log I'm receiving the message when I deploy:

{"@type":"type.googleapis.com/google.cloud.audit.AuditLog","status":{"code":9,"message":"FAILED_PRECONDITION"},"authenticationInfo":{"principalEmail":"*************"},"requestMetadata":{"callerIp":"186.216.140.62","callerSuppliedUserAgent":"FirebaseCLI/6.5.0,gzip(gfe),gzip(gfe)","requestAttributes":{"time":"2019-03-29T23:21:10.130Z","auth":{}},"destinationAttributes":{}},"serviceName":"cloudfunctions.googleapis.com","methodName":"google.cloud.functions.v1.CloudFunctionsService.UpdateFunction","authorizationInfo":[{"permission":"cloudfunctions.functions.update","granted":true,"resourceAttributes":{}},{"resource":"projects/pppppp-9800a/locations/us-central1/functions/sendVerificationEmail","permission":"cloudfunctions.functions.update","granted":true,"resourceAttributes":{}}],"resourceName":"projects/pppppp-9800a/locations/us-central1/functions/sendVerificationEmail","request":{"@type":"type.googleapis.com/google.cloud.functions.v1.UpdateFunctionRequest","function":{"labels":{"deployment-tool":"cli-firebase"},"eventTrigger":{"eventType":"providers/cloud.firestore/eventTypes/document.create","resource":"projects/pppppp-9800a/databases/(default)/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"}}}

My code:

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: '[email protected]',
      pass: 'password'
    }
  };

  var transporter = nodemailer.createTransport(smtpConfig);

  var mailOptions = {
    from: "[email protected]", // 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;
}

When I the the command firebase deploy I get the message functions: failed to update function sendVerificationEmail HTTP Error: 400, Change of function trigger type or event provider is not allowed

I'm new in JS and I don't know what these erros mean

1 Answer 1

0

Delete your first function called sendVerificationEmail, then redeploy. It looks like you maybe initially deployed it as something other than a Firestore trigger.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.