node.js - Firebase 云函数说 Unreachable 并且每个 then() 应该返回一个值或抛出 promise/always-return

标签 node.js firebase firebase-cloud-messaging

Firebase 云函数的 Javascript 代码给出了为推送通知编写的错误

索引.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 error 无法访问的代码 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.      

最佳答案

希望一切顺利,你应该这样回来

return console.log('This is the notify feature');

关于node.js - Firebase 云函数说 Unreachable 并且每个 then() 应该返回一个值或抛出 promise/always-return,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49841484/

相关文章:

node.js - 寻找一种更好的方法来进行实时库存更新

javascript - Firebase排行榜排名

网站的 Firebase 注册 token

android - 无法添加 FCM : failed to resolve com. google.firebase :firebase-auth:9. 0.2,尽管我已经更新了我的 google play 服务

javascript - 将 2 个图像与 node.js 和 gm 合并

node.js - 如何在 Multer-s3 中使用动态存储桶名称进行文件上传

swift - 无法通过 Facebook 从经过身份验证的用户那里获取电子邮件

android - WebStorm 上的 Firebase 设置

Android - GCM 服务器 key 不适用于 Urban Airship

node.js - 在 SailsJS 中设计更薄的 Controller