【发布时间】:2018-03-11 04:53:33
【问题描述】:
我正在尝试为我的应用使用 Firebase 推送通知服务。为此,我在我的应用程序中设置了 firebase 推送通知依赖项,并且还安装了 node.js 和 firebase 工具。当我在目录上使用 firebase deploy 来部署功能时,我收到此错误
40:14 warning Avoid nesting promises promise/no-
nesting
41:25 error Each then() should return a value or throw promise/always-
return
✖ 2 problems (1 error, 1 warning)
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.
这是 index.js 文件
'use strict'
const functions = require('firebase-functions');
const admin = require ('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/Notifications/{receiver_id}/{notification_id}')
.onWrite(event =>
{
const receiver_id = event.params.receiver_id;
const notification_id = event.params.notification_id;
console.log('We have a notification to send to : ', receiver_id);
if(!event.data.val())
{
return console.log('A notification has been deleted from the database : ', notification_id);
}
const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`).once('value');
return deviceToken.then(response =>
{
const token_id = result.val();
const payload =
{
notification:
{
title: "Friend Request",
body: "You have a new friend request",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
console.log('This was the notification feature');
});
});
});
我该如何解决这个问题?我的朋友使用相同的代码,它成功上传,没有错误
【问题讨论】:
标签: firebase firebase-realtime-database push-notification