Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从firestore的云功能中获取用户的电子邮件?_Javascript_Firebase_Google Cloud Functions_Google Cloud Firestore - Fatal编程技术网

Javascript 如何从firestore的云功能中获取用户的电子邮件?

Javascript 如何从firestore的云功能中获取用户的电子邮件?,javascript,firebase,google-cloud-functions,google-cloud-firestore,Javascript,Firebase,Google Cloud Functions,Google Cloud Firestore,以下是用于发送欢迎电子邮件的javascript: const functions = require('firebase-functions'); const nodemailer = require('nodemailer'); const userID = firestore.auth().currentUser.getId(); exports.sendWelcomeEmail = functions.firestore.document('Users/{userID}').o

以下是用于发送欢迎电子邮件的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);
    });
}
const functions=require('firebase-functions');
const nodemailer=require('nodemailer');
const userID=firestore.auth().currentUser.getId();
exports.sendWelcome电子邮件=
functions.firestore.document('Users/{userID}').onCreate(异步事件=>{
const name=event.data.data().name;
const email=event.data.data().email;
返回sendWelcomeEmail(电子邮件、姓名);
})
功能sendWelcomeEmail(电子邮件,名称){
常量邮件选项={
发件人:`${APP_NAME}`,
致:电邮:,
};
mailpoptions.subject=`欢迎使用${APP_NAME}!`;
mailpoptions.text=`Hey${name | |''''}!欢迎来到${APP|u name}。我希望如此
您将享受我们的服务;
返回mailTransport.sendMail(mailpoptions)。然后(()=>{
返回console.log('新的欢迎电子邮件发送到:',电子邮件);
});
}
我有firestore数据库,如用户>用户ID>名称、电子邮件


请帮我解决这个问题。

正如@ArnavRao所说,您应该像以前一样检索数据。它是正确的,您不需要上面的这一行:
constuserid=firestore.auth().currentUser.getId()但如果您确实需要用户Id:

...
const name = event.data.data().name;
const email = event.data.data().email;
const userId = event.params.userID;
...

将为您提供新记录的id。

在您的代码中的什么位置,您需要该id?当记录正确创建时,您已经在从firestore读取电子邮件。当我创建事件时,我需要userID作为路径“Users/{userID}”。否则,它(userId)的值是多少?