Reputation: 2531
I am implementation notifications of firebase in my app. This is my node.js function
'use strict'
const functions = require('firebase-functions');
const admin=require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
My firebase db structure is
Error in Functions is
Please help me . Thanks in advance
Upvotes: 0
Views: 47
Reputation: 13129
Change your code
From this
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').
onWrite(event => {
const userKey = event.params.userKey;
const notification = event.params.notification;
console.log('The userKey is ', userKey);
});
To this
exports.sendNotificaiton=functions.database.ref('/Notifications/{userKey}/{notification_id}').onWrite((change, context) => {
const userKey = context.params.userKey;
const notification = context.params.notification;
console.log('The userKey is ', userKey);
});
You are using the old event
trigger for onWrite()
, now you need to pass context and your dataSnapshot (change).
Also onWrite
has before
and after
values when a write event triggers your database
check the docs here : https://firebase.google.com/docs/functions/database-events?hl=en
See the notification example on github for notifications: https://github.com/firebase/functions-samples/tree/Node-8/fcm-notifications
Upvotes: 2