Firebase Cloud Function Won't Deploy

Viewed 38

I am trying to deploy a callable firebase cloud function to generate an email verification link and then send an email with sendgrid containing the link.

When I deploy I keep getting the error

"code":3,"message":"Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause".

I have succesfully deployed 4 other functions so my firebase & other env variables do not seem to be the problem.

Here is my code:

const functions = require("firebase-functions");

const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

const sgMail = require('@sendgrid/mail');

const API_KEY = functions.config().sendgrid.key;

const TEMPLATE_ID = functions.config().sendgrid.template;

sgMail.setApiKey(API_KEY);


exports.sendEmailVerifications = functions.https.onCall((email,context) => {
  admin.auth().generateEmailVerificationLink(context.auth.token.email).then((link) => {
    const msg = {
      to: context.auth.token.email,

      from: 'example@example.com',

      template: TEMPLATE_ID,

      dynamic_template_data: {

       emailLink: link
      }
  };

    sgMail.send(msg);

    return {"success": true};

  }).catch((error) => {
  
  });
  
});

0 Answers
Related