I am trying to do a simple hello world firebase function with my mobile app, I want to log the user ID so I can see that the function does work. This is my current javascript code:
const functions = require(\'firebase-functions\');
const admin = require(\'firebase-admin\');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref(\'/notifications/{user_id}\').onWrite((event) => {
console.log(\'Testing stuff\', event.params.user_id);
return;
});
It does trigger when new data is written to specific databasetable but this error shows up:
TypeError: Cannot read property \'user_id\' of undefined
at exports.sendNotification.functions.database.ref.onWrite (/user_code/index.js:8:44)
at Object.<anonymous> (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27)
at next (native)
at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71
at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36)
at /var/tmp/worker/worker.js:700:26
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
The notification database looks like this: