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.