Alex L
Alex L

Reputation: 35

Need an assistance with Firebase Cloud Function

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.

Upvotes: 0

Views: 304

Answers (2)

Rémi C.
Rémi C.

Reputation: 339

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!

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 600116

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(...

Upvotes: 1

Related Questions