I am using firebase database to store my iOS app data.
I am saving user tracking data in this app which is working fine.
I have to send a push notification to the user (userID = 57411405) using push token which I am saving in 'IOS' field.
This cloud function I am using :
This cloud function is working fine. I am able to track event which save new tracking data. Here is log of this cloud function:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
exports.databasechanges = functions.database.ref('/users/{id}/LocationTracking').onWrite(event =>{
var eventSnapshot = event.data
console.log('UserId - ', event.params.id);
const userID = event.params.id
const root = event.data.ref.root
admin.database().ref('users/{id}/NotificationToken').on('value').then((snapshot) => {
var token = snapshot.val().IOS;
console.log('token',token)
return snapshot.val();
}).catch(error => {
console.error(error);
res.error(500);
});
return eventSnapshot.val()
});
But on cloud function console I am getting this error:
Now, I am not able to figure out how to access this push token (IOS) and send push notification using cloud function.