【发布时间】:2018-05-09 10:08:24
【问题描述】:
我无法从云功能发送欢迎电子邮件。每当在我的 Firestore 中创建一个新用户时,使用路径为 Users/userId 的“用户”集合。这是我的函数
exports.welcomeEmail = functions.firestore.document('Users/{userId}')
.onCreate((snap, context)=>{
const userId = context.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: 'cybertronjc3@gmail.com',
subject: 'Welcome to COFOZ',
templateId: '1c455865-4529-4ae1-8e5a-9a5b8eaf0157',
substitutionsWrappers: ['{{', '}}'],
substitutions: {
name: user.name
}
};
return sgMail.send(msg)
})
.then(() => console.log('email sent!'))
.catch(err => console.log(err))
})
这是我遇到的错误。
TypeError: Cannot read property 'userId' of undefined
at exports.welcomeEmail.functions.firestore.document.onCreate.event (/user_code/index.js:19:32)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:710:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
【问题讨论】:
标签: firebase cloud google-cloud-firestore google-cloud-functions