Android 上的 Firebase 通知会产生类型错误:无法读取 null 的属性'from'



我需要帮助我几天困扰我的错误:

sendnotification typeerror:无法从null中读取属性'在sender_id.then.fromuserresult(/user_code/index.js:25:48(在process._tickdomaincallback(内部/process/next_tick.js:135:7(

'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}/{notication_id}')
  .onWrite(event => {
    const receiver_id = event.params.receiver_id;
    const notification_id = event.params.notification_id;
    console.log('Temos uma notificação para: ', receiver_id);
    if (!event.data.val()) {
      return console.log('A notificação foi deletada do Banco de dados:', notification_id);
    }
    const sender_id = admin.database().ref(`/Notifications/${receiver_id}/${notification_id}`).once('value');
    return sender_id.then(fromUserResult => {
      const from_sender_id = fromUserResult.val().from;
      console.log('Voce tem uma notificação de:', from_sender_id);
      const senderUserQuery = admin.database().ref(`/Users/${from_sender_id}/user_name`).once('value');
      return senderUserQuery.then(senderUserNameResult => {
        const senderUserName = senderUserNameResult.val();
        const deviceToken = admin.database().ref(`/Users/${receiver_id}/device_token`).once('value');
        return deviceToken.then(result => {
          const token_id = result.val();
          const payload = {
            notification: {
              title: "Notificação",
              body: `${senderUserName} lhe enviou uma solicitação.`,
              icon: "default"
            }
          };
          return admin.messaging().sendToDevice(token_id, payload)
            .then(response => {
              console.log('Processo de notificação.');
            });
        });
      });
    });
  });

停止并启动firebase函数并起作用,:/

相关内容

  • 没有找到相关文章

最新更新