В моем проекте Angular я впервые работаю с функциями Google Cloud в Firebase, и у меня возникла проблема в этой строке: const userId = event.params.userId;
ОШИБКА В МОИХ ЛОГАДАХ:
TypeError: Невозможно прочитать свойство 'userId' из неопределенного в exports.firestoreEmail.functions.firestore.document.onCreate.event (/user_code/index.js:16:32) в cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) в cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) в / var / tmp/worker/worker.js:733:24 at process._tickDomainCallback (внутренняя / process / next_tick.js: 135: 7)
Если я сделаю следующее const userId = "6j1lvREbZwFEfzzJxQg7";
, все будет работать отлично.
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
const SENDGRID_API_KEY =
"SECRET API KEY";
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(SENDGRID_API_KEY);
exports.firestoreEmail = functions.firestore
.document("users/{userId}/followers/{followerId}")
.onCreate(event => {
const userId = event.params.userId;
const db = admin.firestore();
return db
.collection("users")
.doc(userId)
.get()
.then(doc => {
const user = doc.data();
const msg = {
to: user.email,
from: "hello@angularfirebase.com",
subject: "New Follower",
// text: `Hey ${toName}. You have a new follower!!! `,
// html: `<strong>Hey ${toName}. You have a new follower!!!</strong>`,
// custom templates
templateId: "d-c66513d40f0e4b79845f63d598df5e07",
substitutionWrappers: ["{{", "}}"],
substitutions: {
name: user.displayName
// and other custom properties here
}
};
return sgMail.send(msg);
})
.then(() => console.log("email sent!"))
.catch(err => console.log(err));
});
Я пытался изменить это на следующее:
event.userId
user.userId
event.data().userId
Это не сработало.