cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

Having issue with starting Firebase Function and a user_id is undefined

Open Emahrb opened this issue 7 years ago • 4 comments

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)

Emahrb avatar Jun 02 '18 07:06 Emahrb

i have facing same error how to resolve it?

ShehryarAhmed avatar Jun 19 '18 17:06 ShehryarAhmed

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 [email protected] 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 .

Emahrb avatar Jun 20 '18 02:06 Emahrb

I am facing the same issue .

arslan555 avatar Jul 31 '18 11:07 arslan555

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

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

razbakov avatar Oct 03 '18 16:10 razbakov