云函数:尝试从云函数"failed to deploy"在 Firestore 上创建用户



我正试图根据http请求访问我的数据库。

在谷歌的api构建器中,我使用node.js16作为运行时。

我试着运行这个代码:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firestore);
const firestoreDB = admin.firestore()

exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase Cloud Functions!");
console.log("function triggered")
});
exports.createUser = functions.firestore.document('Users/asddsa')
.onCreate((snap, context) => {
const newValue = snap.data();
if (snap.data() === null) return null;
const uid = context.params.userId
let notificationCollectionRef = firestoreDB.collection('Users').doc(uid).collection('Notifications')
return notificationCollectionRef.add({
notification: 'Hello Notification',
notificationType: 'Welcome'
}).then(ref => {
return console.log('notification successful', ref.id)
})
});

但我甚至无法部署它,它只是声明";部署失败";。

现在,这通常是当代码中出现拼写错误时。但我猜我没有事先建立起与消防站的连接。(我从来没有给它密码或任何东西(

我以为在同一个项目中,连接会以任何一种方式工作,但也许我错了?

如何设置连接以创建用户,而不会导致部署失败?

初始设置的说明,用于配置和设置Firebase项目的云功能。您可以查看Firebase文档。

您可以在Cloud firestore触发器中查看详细信息。它描述了事件触发器,在该触发器中,您可以通过使用onCreate((在集合中创建新文档时触发函数来激发。每次添加新的用户配置文件时,此函数都会调用createUser。

此外,您可以查看Github链接来创建用户。

最新更新