当应用使用电话验证进行身份验证时,使用Google Cloud Functions发送欢迎电子邮件

时间:2018-12-10 16:27:44

标签: firebase firebase-realtime-database google-cloud-functions

我正在尝试使用Google Cloud Functions发送欢迎电子邮件,类似于此处所做的事情:

https://github.com/firebase/functions-samples/tree/master/quickstarts/email-users

问题是我的应用程序使用电话验证进行身份验证,但是我们确实上传了用户电子邮件,并将其保存在Firebase实时数据库中的用户UID下。

我们能否使用UID使用云功能提取电子邮件,然后将其插入到javascript代码中?还是有另一种方法?

最好

Feras A。

1 个答案:

答案 0 :(得分:1)

您应该能够使用Firebase Admin SDK从实时数据库中进行读取:

return admin.database().ref(/* path to user's email */).once("value").then(function(snapshot) {
  if (snapshot.val() === null) {
    console.log("Error getting user email: user does not exist");
    return;
  }

  const email = snapshot.child("email").val();

  // Send email here
});

更多信息和示例可以在Firebase Admin Auth Guide上找到(请参见Authenticate with admin privileges下的示例)。