I have 2 trigger functions in an index.js file.

const functions = require("firebase-functions"); //const addTrxns = require("./trxnAdd.js"); const admin = require("firebase-admin"); const { user } = require("firebase-functions/lib/providers/auth"); const { event } = require("firebase-functions/lib/providers/analytics"); //exports.addTrxns.addTrxns; admin.initializeApp(); const db = admin.firestore(); exports.userProfileChanged = functions.firestore.document('/agents/{userId}').onWrite( async (change, context) => { const userId = context.params.userId; console.log('A change has been made to user profile'); const getUserDeviceToken = await db.collection('device').doc(userId).get(); . . . return Promise.all(console.log('End of function')); }); /* ======================================================================== */ exports.onTrxnCreate = functions.document('/trxns/{trxnId}').onCreate((snap, context) => { const userId = context.params.userId; console.log('A new transaction has been added'); const getUserDeviceToken = await **db.collection('device').doc(userId).get();** return Promise.all(console.log('End of function')); }); 

I get this error, "Parsing error: Unexpected token db" in the second function. I think it has something to do with the "await" but I don't know enough about this to fix it. How can I fix this error? Thanks.

1 Answer

I figured this out. I was missing "async" in the second function.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.