【发布时间】:2018-09-25 06:12:56
【问题描述】:
Firebase 云函数的 Javascript 代码给出了为推送通知编写的错误
index.js
'use strict'
//Install functions and admin sdks'
const functions = require('firebase-functions');
const admin =require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) => {
//onwrite will run if data changed
const user_id = context.params.user_id;
const notification = context.params.notification;
if (context.params === null) {
return console.log("Notification Has Been Deleted");
}
let token_id = null;
const deviceToken = admin.database.ref(`/Users/${user_id}/device_token`).once('value');
return deviceToken.then(result => {
token_id = result.val();
const payload = {
notification:{
title:"Friend Request",
body:"You have recieved a new friend request",
icon:"default"
}
};
});
return admin.messaging().sendToDevice(token_id, payload).then(response =>{
console.log('This is the notify feature');
}).catch(err => {
console.log('Error getting documents', err);
});
});
运行 firebase deploy 命令时出现如下错误。如果有人可以支持,我将不胜感激。
错误
error 每个 then() 都应该返回一个值或者抛出 promise/always-return 错误无法访问的代码 no-unreachable error 每个 then() 都应该返回一个值或抛出 promise/always-return
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.
【问题讨论】:
标签: node.js firebase firebase-cloud-messaging