0
votes

I'm trying to write a cloud function using node.js and I'm getting this error:

TypeError: Cannot read property 'user_id' of undefined at exports.FindRoom.functions.database.ref.onWrite (/user_code/index.js:299:39) at Object. (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)

From this function:

exports.FindRoom = functions.database.ref(`/FindRoom/{user_id}`).onWrite((event) =>{
        var user_id = event.params.user_id;
        console.log("user_id",user_id);
        var user_question = event.data.val();
        console.log("user_question",user_question);
        if (!event.data.val()) {
          return console.log('A game room was deleted from database',user_id);
        }

It's a first time I'm using Firebase and Cloud Functions, and the function worked well before I made npm update for Firebase. After update I'm getting this error and could not find a solution.

2
I believe this question was already asked? stackoverflow.com/questions/49647170/… - Doug Stevenson

2 Answers

0
votes

I am not 100% sure but Firebase just got updated to its v1 and it changes stuff about database. I received an email this morning. You can see the changes over here.

Hope it helps!

1
votes

The path string needs to be a literal string, not a template. So replace the backticks (`) with regular (single or double) quotes:

exports.FindRoom = functions.database.ref("/FindRoom/{user_id}").onWrite(...