gpt4 book ai didi

javascript - 我试图通过 Firebase 云功能发出通知,但我的代码没有发出任何通知

转载 作者:行者123 更新时间:2023-12-03 03:47:10 25 4
gpt4 key购买 nike

我已经完成了身份验证触发器,它工作正常。如果有人删除他们的帐户,我需要发送通知“此用户删除了他的帐户(电子邮件)”。这是我的代码

const functions = require('firebase-functions')

//initialize the app
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)

const ref = admin.database().ref()

//create user account function
exports.createUserAccount = functions.auth.user().onCreate(event => {
const uid = event.data.uid
const email = event.data.email

const newUserRef = ref.child(`/UserNotify/${uid}`)
return newUserRef.set({
email: email
})
})

//delete user account function
exports.cleanupUserData = functions.auth.user().onDelete(event => {
const uid = event.data.uid
const userRef = ref.child(`/UserNotify/${uid}`)
return userRef.update({isDeleted: true})
})

function sendNotification() {

console.log("Successfully sent");

var payload = {
notification: {
title: "User get deleted",
body: "sample@gmail.com"
}
};

admin.messaging().sendToDeveice(payload)
.then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
})
}

最佳答案

您可能有输入错误admin.messaging().sendToDevice() 而不是 sendToDeveice

检查:https://firebase.google.com/docs/cloud-messaging/admin/send-messages

关于javascript - 我试图通过 Firebase 云功能发出通知,但我的代码没有发出任何通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45341365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com