I'm currently exploring cloud functions and trying to implement email notifications for document creation triggers in Firestore. I found a helpful tutorial that guided me through the process, but I encountered an error while analyzing the cloud functions logs.
The error message:
{
"severity": "WARNING",
"message": "Function returned undefined, expected Promise or value"
}
The function code:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
const { firestore } = require("firebase-admin/firestore");
const nodemailer = require("nodemailer");
admin.initializeApp();
const transporter = nodemailer.createTransport({
host: process.env.REACT_HOST,
port: 465,
secure: true,
auth: {
user: process.env.REACT_OUTGOING_EMAIL,
pass: process.env.REACT_EMAIL_PASSWORD,
},
});
exports.ProfileCreationEmail = functions.firestore
.document(`profiles/{profile}`)
.onCreate((snap, context) => {
const mailOptions = {
from: ` "Heita Admin" ${process.env.REACT_OUTGOING_EMAIL}`,
to: `${process.env.REACT_OUTGOING_EMAIL}`,
subject: `New Professional Profile Signup`,
html: `<h1>New Profile Created</h1>
<p>
<b>User Name: </b>${snap.data().userName}<br>
</p>
<p>
<b>Email: </b>${snap.data().email}<br>
</p>
`,
};
return transporter.sendMail(mailOptions, (error, data) => {
if (error) {
console.log("Error from sending mail: ", error);
return;
}
console.log("Profile Creation Sent!");
});
});
- What repercussions could this error have?
- How can I resolve it by returning a promise or a value?