Firebase cloud function TypeError: Cannot read property 'ref' of undefined









up vote
0
down vote

favorite












I use firebase real time database and firebase cloud I tried the if users pushid below have expoToken,I wrote the message the pushnotification/id and send the message with expoToken,(I write react native with expo I try the send a push notification)that is my use case anyway just my problem is I run this function and give me an TypeError: Cannot read property 'ref' of undefined error, how can I fix this



const functions = require('firebase-functions');
var fetch = require('node-fetch');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendPushNotification = functions.database
.ref('pushnotification/id')
.onCreate(event =>
const root = event.data.ref.root;

var messages = ;
return root
.child('/users')
.once('value')
.then(function(snapshot)
snapshot.forEach(function(childSnapshot)
var expoToken = childSnapshot.val().expoToken;
if (expoToken)
messages.push(
to: expoToken,
body: 'New node Added'
);

);
return Promise.all(messages);
)
.then(() =>
fetch('https://exp.host/--/api/v2/push/send',
method: 'POST',
headers:
Accept: 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringfy(messages)
);
);
);









share|improve this question





















  • Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
    – Doug Stevenson
    Nov 10 at 21:55














up vote
0
down vote

favorite












I use firebase real time database and firebase cloud I tried the if users pushid below have expoToken,I wrote the message the pushnotification/id and send the message with expoToken,(I write react native with expo I try the send a push notification)that is my use case anyway just my problem is I run this function and give me an TypeError: Cannot read property 'ref' of undefined error, how can I fix this



const functions = require('firebase-functions');
var fetch = require('node-fetch');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendPushNotification = functions.database
.ref('pushnotification/id')
.onCreate(event =>
const root = event.data.ref.root;

var messages = ;
return root
.child('/users')
.once('value')
.then(function(snapshot)
snapshot.forEach(function(childSnapshot)
var expoToken = childSnapshot.val().expoToken;
if (expoToken)
messages.push(
to: expoToken,
body: 'New node Added'
);

);
return Promise.all(messages);
)
.then(() =>
fetch('https://exp.host/--/api/v2/push/send',
method: 'POST',
headers:
Accept: 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringfy(messages)
);
);
);









share|improve this question





















  • Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
    – Doug Stevenson
    Nov 10 at 21:55












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use firebase real time database and firebase cloud I tried the if users pushid below have expoToken,I wrote the message the pushnotification/id and send the message with expoToken,(I write react native with expo I try the send a push notification)that is my use case anyway just my problem is I run this function and give me an TypeError: Cannot read property 'ref' of undefined error, how can I fix this



const functions = require('firebase-functions');
var fetch = require('node-fetch');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendPushNotification = functions.database
.ref('pushnotification/id')
.onCreate(event =>
const root = event.data.ref.root;

var messages = ;
return root
.child('/users')
.once('value')
.then(function(snapshot)
snapshot.forEach(function(childSnapshot)
var expoToken = childSnapshot.val().expoToken;
if (expoToken)
messages.push(
to: expoToken,
body: 'New node Added'
);

);
return Promise.all(messages);
)
.then(() =>
fetch('https://exp.host/--/api/v2/push/send',
method: 'POST',
headers:
Accept: 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringfy(messages)
);
);
);









share|improve this question













I use firebase real time database and firebase cloud I tried the if users pushid below have expoToken,I wrote the message the pushnotification/id and send the message with expoToken,(I write react native with expo I try the send a push notification)that is my use case anyway just my problem is I run this function and give me an TypeError: Cannot read property 'ref' of undefined error, how can I fix this



const functions = require('firebase-functions');
var fetch = require('node-fetch');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.sendPushNotification = functions.database
.ref('pushnotification/id')
.onCreate(event =>
const root = event.data.ref.root;

var messages = ;
return root
.child('/users')
.once('value')
.then(function(snapshot)
snapshot.forEach(function(childSnapshot)
var expoToken = childSnapshot.val().expoToken;
if (expoToken)
messages.push(
to: expoToken,
body: 'New node Added'
);

);
return Promise.all(messages);
)
.then(() =>
fetch('https://exp.host/--/api/v2/push/send',
method: 'POST',
headers:
Accept: 'application/json',
'Content-Type': 'application/json'
,
body: JSON.stringfy(messages)
);
);
);






javascript node.js firebase react-native google-cloud-functions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 18:27









Radex26

175




175











  • Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
    – Doug Stevenson
    Nov 10 at 21:55
















  • Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
    – Doug Stevenson
    Nov 10 at 21:55















Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
– Doug Stevenson
Nov 10 at 21:55




Are you following an old tutorial? It's using a very old version of the Cloud Functions for Firebase API, but you're building against a newer version.
– Doug Stevenson
Nov 10 at 21:55

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242109%2ffirebase-cloud-function-typeerror-cannot-read-property-ref-of-undefined%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242109%2ffirebase-cloud-function-typeerror-cannot-read-property-ref-of-undefined%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線