googlearchive / cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki
Apache License 2.0
826 stars 114 forks source link

Having issue with starting Firebase Function and a user_id is undefined #211

Open Emahrb opened 6 years ago

Emahrb commented 6 years ago

Here is my index.js file :

'use-strict'

const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(functions.config().firebase);

exports.sendNotification = functions.firestore.document("Users/{user_id}/Notification/{notification_id}").onWrite(event=> {

const user_id = event.params.user_id; const notification_id = event.params.notification_id;

console.log("User ID : "+ user_id + " | Notification ID : " + notification_id);

});

And, here is the Error :

Function execution took 1336 ms, finished with status: 'error'

TypeError: Cannot read property 'user_id' of undefined at exports.sendNotification.functions.firestore.document.onWrite.event (/user_code/index.js:8:31) at Object. (/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:716:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)

ShehryarAhmed commented 6 years ago

i have facing same error how to resolve it?

Emahrb commented 6 years ago

still I have no perfect solution :( If I got something , I will let you :D

On Tue, Jun 19, 2018 at 11:24 PM shehryar Ahmed notifications@github.com wrote:

i have facing same error how to resolve it?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/GoogleCloudPlatform/cloud-functions-emulator/issues/211#issuecomment-398479256, or mute the thread https://github.com/notifications/unsubscribe-auth/AiZBRgx8RKpbQBBHAcBWBiu4RZkztISTks5t-TPdgaJpZM4UXmKs .

arslan555 commented 6 years ago

I am facing the same issue .

razbakov commented 5 years ago

Have you tried to use the same way as in shown in doc?

// ...
.onWrite((change, context) => {
   const user_id = context.params.user_id;
   // ...