简体   繁体   English

如何在功能区中从Firestore获取用户的电子邮件?

[英]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.

相关问题 我无法从Firebase Firestore中的Firebase云功能写入数据 - I can not write data from the Firebase Cloud Functions in Firebase Firestore 如何使用 Firestore 在 Cloud Functions for Firebase 中获取服务器时间戳? - How do I get the server timestamp in Cloud Functions for Firebase with Firestore? 如何从 Firestore 获取数据到谷歌云功能? - How to get data from firestore to google cloud functions? 如何从 Firestore 获取当前用户的文档? - How can I get documents from Firestore for current user? 如果我有来自 Cloud Firestore 的其他自定义数据,如何获取用户数据? - How do I get user data if I have other custom data from cloud firestore? Cloud Functions 从 firestore 路径获取列表 - Cloud Functions get list from firestore path Cloud Functions - Cloud Firestore 错误:无法获取 serverTimestamp - Cloud Functions - Cloud Firestore error: can't get serverTimestamp 我可以在节点 8 的 Cloud Functions 中使用 Cloud Firestore 触发器吗? - Can i use Cloud Firestore triggers in Cloud Functions with node 8? 如何通过Angular中的路由在Cloud Functions中对Cloud Firestore执行添加? - How can I execute an add to Cloud Firestore in Cloud Functions through routes in Angular? 如何获取包含字符串的数组的文档? 云Firestore和云功能 - How to get documents with an array that contains a string? Cloud Firestore & Cloud Functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM