Reputation: 829
Hi This firebase function use to work, but know its now longer working and I'm getting this error message
Function returned undefined, expected Promise or value
exports = module.exports = functions.analytics.event('first_open').onLog((event) => {
const payload = {
notification: {
title: 'you have a new user \uD83D\uDE43',
body: event.data.user.deviceInfo.mobileModelName + ' from ' + event.data.user.geoInfo.city + ', ' + event.data.user.geoInfo.country,
sound:"default",
vibrate:"true"
},
};
admin.messaging().sendToDevice(deviceToken, payload);
});
Upvotes: 0
Views: 383
Reputation: 1840
In firebase functions, you should return a Promise or a value. You can return a value if your function is already finished. If your work has still has ongoing work you must return a Promise, which should be resolved once the work is done.
In your scenario, you have admin.messaging().sendToDevice(deviceToken, payload);
which is not finished at the end of the method. So you should return a promise which is resolved once the work is done. Luckily admin.messaging().sendToDevice(deviceToken, payload);
itself returns a promise. So you can just return it from the function as following.
return admin.messaging().sendToDevice(deviceToken, payload);
Upvotes: 2
Reputation: 80924
change this:
admin.messaging().sendToDevice(deviceToken, payload);
to this:
return admin.messaging().sendToDevice(deviceToken, payload);
Upvotes: 3