这是我的第一个firebase的javascript函数。
TypeError:无法读取未定义
的属性'uid'
我在firebase云功能中遇到此错误。如何解决?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.grantSignupReward = functions.database.ref('/users/{uid}/last_signin_at')
.onCreate(event => {
const uid = event.params.uid;
admin.database().ref(`users/${uid}/referred_by`)
.once('value').then((data) => {
var referred_by_somebody = data.val();
if (referred_by_somebody) {
var moneyRef = admin.database().ref(`/users/${uid}/earned`);
moneyRef.transaction((current_value)=> {
return (current_value || 0) + 10;
});
}
return console.log('reddem updated')
}).catch(error => {
console.log("Got an error: ",error);
});
});
答案 0 :(得分:4)
云功能已更新,因此您需要更改此内容:
exports.grantSignupReward = functions.database.ref('/users/{uid}/last_signin_at')
.onCreate(event => {
const uid = event.params.uid;
进入这个:
exports.grantSignupReward = functions.database.ref('/users/{uid}/last_signin_at')
.onCreate(snap,context) => {
const uid = context.params.uid;
更多信息:
https://firebase.google.com/docs/functions/beta-v1-diff#realtime-database