[英]how can I get the email of the user from firestore in cloud functions?
Here is the javascript for sending welcome email: 这是用于发送欢迎电子邮件的JavaScript:
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
const userID = firestore.auth().currentUser.getId();
exports.sendWelcomeEmail =
functions.firestore.document('Users/{userID}').onCreate(async event => {
const name = event.data.data().name;
const email = event.data.data().email;
return sendWelcomeEmail(email, name);
})
function sendWelcomeEmail(email, name) {
const mailOptions = {
from: `${APP_NAME} <jagdish.choudhary@iitgn.ac.in>`,
to: email,
};
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey ${name || ''}! Welcome to ${APP_NAME}. I hope
you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
return console.log('New welcome email sent to:', email);
});
}
I have firestore database like Users > userID > name,email. 我有Firestore数据库,例如用户>用户ID>名称,电子邮件。
Please help me with this. 请帮我解决一下这个。
As @ArnavRao said, you should retrieve the data as you did. 正如@ArnavRao所说,您应该像以前那样检索数据。 It seams correct and you don't need this line above : const userID = firestore.auth().currentUser.getId();
它正确无误,您在上面不需要此行: const userID = firestore.auth().currentUser.getId();
But if you need definitely the user Id: 但是,如果您绝对需要用户ID:
...
const name = event.data.data().name;
const email = event.data.data().email;
const userId = event.params.userID;
...
will give you new record's id. 将为您提供新记录的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.