I'm a beginner at nodeJs but trying to connect to cloud server to send notification trough firebase cloud notifications
// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');
// The Firebase Admin SDK to access the Firebase Realtime Database.
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.helloWorld = functions.https.onRequest((request, response) => {
response.send("Hello from the ProjectSupporter Team");
});
exports.sendPushNotifications = functions.https.onRequest((req, res) => {
res.send("Attempting to send push notification...")
console.log("LOGGER --- Trying to send push message...")
// admin.message().sendToDevice()
var uid = 'Ky6h0BgpGDNMUyyBgE4ul99MzXk1'
return admin.database().ref('/users/' + uid).once('value', async snapshot => {
var user = snapshot.val();
console.log("User username: " + user.username + " fcmToken: " + user.fcmToken);
// See documentation on defining a message payload.
var message = {
notification: {
title: "Push Notification Title",
body: "Message Body..."
},
data: {
score: '850',
time: '2:45'
},
token: user.fcmToken
};
// Send a message to the device corresponding to the provided
// registration token.
try {
const response = await admin.messaging().send(message);
console.log('Successfully sent message:', response);
} catch(e) {
console.log('Error sending message:', error);
}
});
This is the error message I'm getting:
20:70 error Parsing error: Unexpected token snapshot
✖ 1 problem (1 error, 0 warnings)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: eslint .
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
My ide Brackets says there is an error on line 20, 70. I can't figure out what the problem is.
Here is an image: https://ibb.co/iBp17H
Thanks in advance!