【发布时间】:2018-10-23 20:30:08
【问题描述】:
我正在尝试编写一个云函数,用于检测何时使用 oncreate((user) 函数创建了新用户,然后将值 50 添加到 points 字段中。 这就是创建的内容:
我要做的只是检测用户何时被创建,获取 ID 并将点值更改为 50,它必须是云功能。 这就是我的代码目前的样子。
exports.updatepoints = functions.auth.user().onCreate((user) => {
const userID = firebase.auth.currentUser.uid;
return updatepoints(userID)
});
async function updatepoints(userID) {
return firebase.database().ref('mobile_user/' + userID).set(
{
points: 50
});
};
我对 JS 和 firebase 还很陌生,因此非常感谢任何指导帮助。
【问题讨论】:
-
这里的标识符
firebase是什么?如果您尝试在 Cloud Functions 中使用 javascript 客户端库,那不是正确的方法。您需要改用管理 SDK。此外,您可能希望从 auth 触发器的文档开始,因为您需要了解user参数是什么。 firebase.google.com/docs/functions/auth-events -
仅供参考,您的
async是多余的 -
用户是使用 Admin/Node SDK 创建的客户端(JavaScript/Web SDK)还是服务器端?
标签: javascript firebase firebase-authentication google-cloud-functions