Chapter Five

Firebase provides more than a dozen of services for both mobile and web app developement. Lets shed some light on 5 basic services today to build an app.

Firebase Authentication:

For every project we require users to authenticate in the system, users credentials to be validated and secured in our database. In order to ease the flow of authentication, authentication using SNS, or social networking sites, is nowadays crucial to ensure easier first entry to the system. And we also need a login page to be created now and then for the same task.

Firebase Authentication not only provides mutiple platforms to log in including the general email login, it also provides a drag and drop ui to get you all started with the login page. Firebase authentication sdk generates unique userId for n number of users, and always maintains the state, so it just takes one promise to know if a user is logged in to the system or not. Features like Forget password, 2 Factor Authentication also come out of the box.

Here is a simple code snippet to highlight the ease of getting login done in Angular apps using @angular/fire :

Firebase Firestore:

Back in 2012, before Google acquired it, Firebase was very well known to developers for their real time database. One updates the store and instantly all the connected devices are in perfect sync. Google announced their Realtime Database back in 2016, and now we have a better version of it, called Firestore.

It is a NoSQL Database that supports query and provides offline support. If a user updates any data offline, it is persisted locally by the sdk and when the connection is up, the store is updated and the rest of the devices are in perfect sync. Firestore supports queries to ensure that the business logic to get the data in the front end is of much ease.

Here you can see how easy it is to subscribe to the user collections snapshot and immediately be notified of the change in the database.

Firebase Cloud Storage:

Now that you have authenticated users store their data in a real time database, you might also need to store contents like files, images etc.

Using Cloud Storage, storing in buckets have never been easier.

This storage securely stores user generated content, and ensures uploads over flaky internet connections and is immensly scaleable.

Firebase Hosting:

firebase deploy

And that is it, you will get your static site with dynamic content hosted with ssl certificate. Fast deployment to a global content delivery network (CDN), options for rollback if you think you need to deploy again, all make deployment just one command away. A series of questions will pop up in your cli regarding the deployment, choose the best answers that fit you and within minutes your production grade site is up.

Firebase CLI is really impressive to not only setup the project but also to deploy the contents.

Cloud Functions:

To simply put, cloud functions are your backend codes. They are dormant in nature, and will spring to life when any event is triggered, that may be in the form of Firebase features or HTTP requests.

Creating Google Cloud functions using Firebase SDK is simple, but for developers, you need to setup an account in Google Cloud Platform to get started.

For instance, the moment a user uploads a image in the storage, you can detect this change via functions.storage().onChange and then decide what to do. Cloud functions will definitely serve as an entry to Google Machine Learning Kit, called ML Kit.

Currently the cloud functions can be tested in local servers, and written only in Node.js and Python, and deploy it in firebase. Functions can be monitored in the Firebase console.