How to Convert Realtime Database Events to Promises in Firebase

firebase

The Realtime Database API in Firebase is based on callbacks. This could be fine for you if you are maintaining a codebase which is a few years old. But, if you prefer a Promise, or better yet async await approach, you will be down for a little disappointment. A typical function that you write for retrieving data from […]

Create User Profile in Firestore After Authentication in Firebase

firebase

When a user signs up for your app, Firebase creates their profile in Firebase Authentication. This is great because most of the hard stuff like OAuth and validation is being handled automatically for you. This, however, has its limitations. Auth doesn’t let you store any custom properties to the user and this is very limited […]

How to Split Cloud Functions Into Multiple Javascript Files in Firebase

firebase

Often times, you may hear that for Node.js development, the code logic should be separated into different modules. This is logical and obviously the best practice whenever you are writing code for the real world. In Firebase Cloud Functions, you can also do that. From your index.js file, simply require() the function from another file and use its reference to […]

Get All Users From Auth in Cloud Functions for Firebase

firebase

To get all the users from auth in Firebase, you can use the Admin SDK for Firebase. It gives you elevated privileges to perform operations in the system that a normal user can not. The Admin SDK comes with a lot of functionality built-in. But, the one thing that we care about here is Managing Users. Getting Users […]

How to Import Large Amount of Data to Cloud Firestore

firebase

Firestore has been out of beta for some time now. But it still doesn’t support import or export functionality natively. This is a big downer for someone wanting to use the native functionality of the Firebase platform. Keep in mind that when I talk about enabling exports/imports, I’m talking about the firebase-admin SDK. Export/Import via the gsutil command-line utility is […]

Get All Dictionary Keys in Firestore Using Firebase Cloud Functions

firebase

In Firebase, you can get all the keys of an Object very easily. The thing that you should note is that a dictionary is just an Object in Firestore. All the custom Objects that you store in the Firestore behave just like the native Javascript objects. To get all keys of an object, you can simply use the Object.keys() method that is available for […]

Protect Firebase Cloud Functions From Unauthorized Access

firebase

In this tutorial, I’ll show you how you can protect your https cloud functions from unauthorized users in Firebase. By restricting unauthorized users, you can save resources and thus decrease the overall cost of your app. Setting Up The Project Using the command-line, initialize the Firebase project as follows: $ mkdir cf-auth $ cd cf-auth […]

How to Get Server Timestamp Using Firebase Cloud Functions

firebase

In this tutorial, we are going to create a Cloud Function which will return the server timestamp. Getting the Firebase Server Timestamp If you only care about the timestamp and not what format it comes in the result, this method is for you. You can simply create an endpoint in your https API which will […]

How to Enforce Unique Field Values in Cloud Firestore

firebase

The Cloud Firestore is an awesome platform for quickly prototyping your app ideas into reality, however, it certainly comes with some limitations. Currently, there is no way for you to enable uniqueness in field values in the whole database. There is a quick workaround, though with queries that you can use. The Problem You want […]