export = module.exports = functions.firestore .document('rootPath/{topDocID}/subcollection/{endDocID}') .onCreate(async (snap, context) => { const groupDocRef = admin.firestore().collection('rootPath').doc(context.params.topDocID); const transaction = admin.firestore().runTransaction(t => { return t.get(groupDocRef) .then(doc => { const newAdminCount = doc.data().adminCount + 1; t.update(groupDocRef, { adminCount: newAdminCount }); if (newAdminCount === 1) { //set claim to role = "admin" admin.auth().setCustomUserClaims(context.params.endDocID, { role: "admin" }) .then(() => { console.log("Role set to: admin"); }).catch(error => { console.log("Error. Role failed to get set: ", error); }); } else { console.log("Error. No role set. Invalid adminCount."); } }); }).then(result => { console.log('Transaction success', result); }).catch(error => { console.log('Transaction failure:', error); }); return Promise.resolve(); });
Transaction failure: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/srv/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/11f68efc-37b9-4606-9dd1-9c1eceb07324%40googlegroups.com.
let transaction = db.runTransaction(t => { return t.get(cityRef)
.then(doc => {
// Add one person to the city population.
// Note: this could be done without a transaction
// by updating the population using FieldValue.increment()
let newPopulation = doc.data().population + 1;
t.update(cityRef, {population: newPopulation});
});
}).then(result => {
console.log('Transaction success!');
}).catch(err => {
console.log('Transaction failure:', err);
});
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fcf843cc-7385-4834-8cff-5afd49f030f3%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to fireba...@googlegroups.com.