Firebase-Device-to-Device-Push-Notification icon indicating copy to clipboard operation
Firebase-Device-to-Device-Push-Notification copied to clipboard

problem with firebase deploy

Open leenorshn opened this issue 7 years ago • 13 comments

hello, teacher ! i have an issue when i am trying to deploy a function witch is in index.js file, a take all your code witch your publish to github for notification, but i have this issue:warning nesting promise promise/no-nesting error Each the() should return a value or throw promise/always-return. Please help me, I'm using FirebaseCloud messaging 11.0.4 and nodev8.4 for windows. i'm dont understand why my code dont work image

leenorshn avatar Feb 06 '18 09:02 leenorshn

Modify in firebase.json from "npm --prefix $RESOURCE_DIR run lint" to "npm --prefix %RESOURCE_DIR% run lint"

It Worked For Me.

muankit avatar Mar 04 '18 13:03 muankit

On Firebase init step, when it asked "Do you want to use ESLint to catch probable bugs and enforce style?" You just say no It should solve your problem

miladxyz avatar Mar 05 '18 01:03 miladxyz

Got error in log :

My index.js is here

`'use strict'

const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.database.ref('/notification/{user_id}/{notification_id}').onWrite(event => {

const user_id = event.params.user_id; const notification = event.params.notification;

console.log("The User Id is : ",user_id);

if(!event.data.val()){

return console.log('A Notification has been deleted from database : ', notification_id);

}

const fromUser = admin.database().ref(/notification/${user_id}/{notification_id}).once(value); return fromUser.then(fromUserResult => {

    const from_user_id = fromUserResult.val().from;
    console.log('You have new notification from : ', from_user_id);

    const userQuery = admin.database().ref(`/Users/${user_id}/${notification_id}`).once('value');
    return userQuery.then(userResult => {

        const userName = userResult.val();
        const deviceToken = admin.database().ref(`/Users/${user_id}/device_token`).once('value');

        return deviceToken.then (result => {

          const token_id = result.val();

          const payload = {
            notification : {

              title : "Friend Request",
              body : `${userName} has sent you request`,
              icon : "default"
            }
          };

          return admin.messaging().sendToDevice(token_id , payload).then(response => {

            console.log('This was the Notifiaction Feature');
            return null;

          });
        });
  });

}); }); ` logs_error

muankit avatar Mar 05 '18 07:03 muankit

sollution for----

error Each then() should return a value or throw 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.

try by editing index.js

use this code--

return admin.messaging().sendToDevice(token_id, payload).then(response => {

    console.log('This was the notification Feature');
    return null;
  }).catch(error => {
console.error(error);
res.error(500);
 });

instead of ---

return admin.messaging().sendToDevice(token_id, payload).then(response => {

    console.log('This was the notification Feature');

  });

Show less

imandal665 avatar Apr 07 '18 12:04 imandal665

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Developer-AP avatar Jul 16 '18 18:07 Developer-AP

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Have you found any solution for this issue??

EngAlaa22 avatar Nov 04 '18 22:11 EngAlaa22

exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };

return admin.database().ref('fcm-token').once('value').then(allToken => {
    if(allToken.val()){
        console.log('token available');
        const token = Object.keys(allToken.val());
        return admin.messaging().sendToDevice(token,payload);
    }else{
       return console.log('No token available');
    }
});

}

----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');

this is because then() should return something

Atominac avatar Jan 24 '19 03:01 Atominac

exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };

return admin.database().ref('fcm-token').once('value').then(allToken => {
    if(allToken.val()){
        console.log('token available');
        const token = Object.keys(allToken.val());
        return admin.messaging().sendToDevice(token,payload);
    }else{
       return console.log('No token available');
    }
});

}

----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');

this is because then() should return something

this one too worked for me thank you Atominac !!!

Prakash-ap avatar Sep 07 '19 04:09 Prakash-ap

exports.helloWorld = functions.database.ref('notification/{id}').onWrite(evt => { const payload = { notification:{ title : 'Message from Cloud', body : 'This is your body', badge : '1', sound : 'default' } };

return admin.database().ref('fcm-token').once('value').then(allToken => {
    if(allToken.val()){
        console.log('token available');
        const token = Object.keys(allToken.val());
        return admin.messaging().sendToDevice(token,payload);
    }else{
       return console.log('No token available');
    }
});

}

----this worked for me instead of: console.log('No token available'); use: return console.log('No token available');

this is because then() should return something

Worked for me too. Thank you man!

atmanad avatar Oct 13 '20 13:10 atmanad

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Have you solve this issue.

cofound-ind-in avatar Jun 18 '21 15:06 cofound-ind-in

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Hi @Developer-AP Are you able to solve?? I have same issue

cofound-ind-in avatar Jun 18 '21 15:06 cofound-ind-in

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Hi @Developer-AP Are you able to solve?? I have same issue

Can you please share the complete error and the code snippet giving this error.

Atominac avatar Jun 21 '21 08:06 Atominac

In my log, I am getting this error! Please help me. It's very important! Thank you! say alap functions firebase console - google chrome 17-07-2018 00_09_31

Hi, please check in your code, you'll find somewhere you are using an object without define it. Your compile is seeing some thing like this undefined.user_id .

Or you can share your code for more details

leenorshn avatar May 07 '22 15:05 leenorshn