I'm still learning about Firebase functions and I've been working on setting up an onCreate() trigger, but I'm having trouble getting it to work.
Could the issue be with how I am handling the promise for Sendgrid? I'm not sure what I'm missing
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const sendGrid = require("@sendgrid/mail");
admin.initializeApp();
const database = admin.database();
const API_KEY = '';
const TEMPLATE_ID = '';
sendGrid.setApiKey(API_KEY);
const actionCodeSettings = {
...
};
exports.sendEmailVerify = functions.auth.user().onCreate((user) => {
admin
.auth()
.generateEmailVerificationLink(user.email, actionCodeSettings)
.then((url) => {
const msg = {
to: user.email,
template_id: TEMPLATE_ID,
dynamic_template_data: {
subject: "test email",
name: name,
link: url,
},
};
return sendGrid.send(msg);
})
.catch((error) => {
console.log(error);
});
});
Event logs from firebase functions
sendEmailVerify
Function execution started
sendEmailVerify
Function returned undefined, expected Promise or value
sendEmailVerify
Function execution took 548 ms, finished with status: 'ok'
sendEmailVerify
{ Error: Forbidden
sendEmailVerify
at axios.then.catch.error (node_modules/@sendgrid/client/src/classes/client.js:133:29)
sendEmailVerify
at process._tickCallback (internal/process/next_tick.js:68:7)
sendEmailVerify
code: 403,
sendEmailVerify
message: 'Forbidden',