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)
);
);
);
javascript node.js firebase react-native google-cloud-functions
add a comment |
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)
);
);
);
javascript node.js firebase react-native google-cloud-functions
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
add a comment |
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)
);
);
);
javascript node.js firebase react-native google-cloud-functions
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
javascript node.js firebase react-native google-cloud-functions
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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