Home > Software engineering >  Firebase realtime database get wildcard data
Firebase realtime database get wildcard data

Time:02-28

I'm trying to send a notification to users whenever their message receives a new reply. However, in the firebase cloud functions logs it is returning errors and not sending a notification. Here is the error:

TypeError: Cannot read properties of undefined (reading 'uid') 

Here is my function:

const functions = require("firebase-functions");
const admin = require("firebase-admin");

exports
    .sendNewTripNotification = functions
        .database
        .ref("messagepool/{uid}/responses/")
        .onWrite((event)=>{
          const messageid = event.params.uid;

          // console.log('User to send notification', uuid);

          const ref = admin.database().ref(`messagepool/${messageid}/author`);
          return ref.once("value", function(snapshot) {
            const ref2 = admin.database().ref(`users/${snapshot.val()}/token`);
            return ref2.once("value", function(snapshot2) {
              const payload = {
                notification: {
                  title: "           
  • Related