【发布时间】:2021-08-05 19:42:01
【问题描述】:
当我需要客户端当前的用户ID时,我可以使用:firebase.auth().currentUser.uid。
如何在云函数中获取当前用户 ID(Pub Sub 触发器)?
exports.sendPushNotification = functions.pubsub.schedule("* * * * *")
.onRun(async (context) => {
const today = new Date();
const date = today.getFullYear()+"-"+(today.getMonth()+1)+
"-"+today.getDate();
const query = await db.collection("posts")
.where("date", "==", date)
.where("idUser", "==", i need here to call my current user id)
.get();
query.forEach(async (snapshot) => {
sendNotification(snapshot.data().idUser, snapshot.data().title);
});
});
【问题讨论】:
-
虽然 dharmaraj 已经回答了您的问题,但是使用 Cloud Firestore
onCreatetrigger 可以更好地实现您使用此触发器的目的,这将为您提供创建的帖子以及创建者。但是,我不确定您为什么要向发布该帖子的人发送有关该帖子的通知。 -
我正在向发布通知的人发送通知,因为他们正在发布发票。并在发票到期日收到推送通知以记住到期日。
-
@WafaBergaoui 我猜您想在用户的发票待处理时向他们发送通知。请分享存储到期数据的发票的 Firestore 文档的屏幕截图。
-
@WafaBergaoui 我添加了一个您可以使用的解决方法,如果答案有帮助,您可以通过单击勾选图标接受它,以便其他人知道它已解决,否则请随时提出更多问题。跨度>
标签: node.js firebase google-cloud-functions google-cloud-pubsub