I am getting value inside token variable but the code is producing error saying that function should return promise or value. the reason for which I would like to access token is to send notification to the receiver about the received request. my problematic code snippet is present below.
const functions = require('firebase-functions');
var admin = require('firebase-admin');
var promise=require('promise');
admin.initializeApp();
exports.sendRequestReceivedNotification=functions
.database
.ref('/Requests/{receiverID}/receivedFrom/{senderID}')
.onCreate((snapshot,context)=>{
const receiverID= context.params.receiverID;
const senderID=context.params.senderID;
console.log(senderID,' sent message to ',receiverID);
admin.database().ref()
.child('DeviceTokens')
.child(receiverID)
.child('deviceToken')
.once('value')
.then(function(snapshot){
var token=snapshot.val();
console.log(token);
return true;
})
.catch(function(error){
return false;
});
});
while deploying, running and triggering the function i am getting the error as shown in the following snapshot. I have googled abut promises, then().catch() structure but could not get the grasp and the illusion has been never clear to me... :(
return undeifned value:
Could someone be kind enough to explain the issue here and remedy to this problem please?