How to protect firebase Cloud Function HTTP endpoint to allow only Firebase authenticated users?

With the new firebase cloud function I’ve decided to move some of my HTTP endpoint to firebase. Everything works great… But i have the following issue. I have two endpoints build by HTTP Triggers (Cloud Functions) An API endpoint to create users and returns the custom Token generated by Firebase Admin SDK. An API endpoint … Read more

How do I structure Cloud Functions for Firebase to deploy multiple functions from multiple files?

I would like to create multiple Cloud Functions for Firebase and deploy them all at the same time from one project. I would also like to separate each function into a separate file. Currently I can create multiple functions if I put them both in index.js such as: exports.foo = functions.database.ref(‘/foo’).onWrite(event => { … }); … Read more

How can I solve the error ‘TS2532: Object is possibly ‘undefined’?

I’m trying to rebuild a web app example that uses Firebase Cloud Functions and Firestore. When deploying a function I get the following error: src/index.ts:45:18 – error TS2532: Object is possibly ‘undefined’. 45 const data = change.after.data(); This is the function: export const archiveChat = functions.firestore .document(“chats/{chatId}”) .onUpdate(change => { const data = change.after.data(); const … Read more

Difference Between Firestore Set with {merge: true} and Update

In Cloud Firestore there are three write operations: add() set() update() In the docs it says that using set(object, { merge: true }) will merge the given object with the existing document. The same happens when you use update(object)… so what is the difference? It seems strange that google would duplicate functionality like this. 5 … Read more

Enabling CORS in Cloud Functions for Firebase

I’m currently learning how to use new Cloud Functions for Firebase and the problem I’m having is that I can’t access the function I wrote through an AJAX request. I get the “No ‘Access-Control-Allow-Origin’” error. Here’s an example of the function I wrote: exports.test = functions.https.onRequest((request, response) => { response.status(500).send({test: ‘Testing functions’}); }) The function … Read more

Separate dev and prod Firebase environment

I am considering using Firebase as MBaaS, however I couldn’t find any reliable solution to the following problem: I would like to set up two separate Firebase environments, one for development and one for production, but I don’t want to do a manual copy of features (eg. remote configuration setup, notification rules, etc.) between the … Read more

How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

I’m starting with the new Google service for the notifications, Firebase Cloud Messaging. Thanks to this code https://github.com/firebase/quickstart-android/tree/master/messaging I was able to send notifications from my Firebase User Console to my Android device. Is there any API or way to send a notification without use the Firebase console? I mean, for example, a PHP API … Read more

firestore: PERMISSION_DENIED: Missing or insufficient permissions

I am getting the Error gettingdocuments.com.google.firebase.firestore.FirebaseFirestoreException: PERMISSION_DENIED: Missing or insufficient permissions. for the below code on else statement db.collection(“users”) .get() .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { if (task.isSuccessful()) { for (DocumentSnapshot document : task.getResult()) { s(document.getId() + ” => ” + document.getData()); } } else { s(“Error getting documents.”+ task.getException()); } … Read more

Failed to resolve: com.google.firebase:firebase-core:9.0.0

I get the following error while upgrading a firebase project from old domain to new google firebase domain. Failed to resolve: com.google.firebase:firebase-core:9.0.0 I followed the steps mentioned on the Firebase documentation, in the section Add Firebase to your Android Project, topic Available libraries. What are my options to resolve this error? 12 Answers 12