Integration of Firebase with Google Cloud Platform (GCP)
Integration of Firebase with Google Cloud Platform (GCP)
Firebase
Firebase is Google’s mobile application development platform and the fastest way to build your App. Firebase is a complete backend solution that can manage authentication, real-time database and hosting as well. It is built on Google infrastructure and scales automatically.
Why we need Firebase for GCP?
Steps to Enable Firebase
- Visit – https://console.firebase.google.com/
- Click on Add project.
- Click on Project name section.
- You will see the projects in the dropdown and click on the project.
- Accept the Terms and conditions and click on the Create project.
- It will redirect you to the firebase home page.
Common infrastructure shared by Firebase and GCP
-
Products:
Cloud function and cloud storage are the two products shared by both GCP and Firebase.
-
Billing:
Firebase and Cloud products can be placed on the same bill.
-
Accounts:
Firebase & GCP both use Google accounts so you can use one google account for both.
-
Project:
You can add both GCP product and firebase to a project.
-
Terms of service:
Some GCP terms of services are used by firebase products. These are Cloud Storage for Firebase, Cloud Functions for Firebase, Cloud Firestore, and Firebase Test Lab.
Authentication
Firebase supports a lot of different ways to authenticate users.Firebase auth has built in functionality for third party providers such as Facebook, twitter, google.Once user authenticates, information of the user is returned to the device via callbacks. The user information contains a unique id and it is used for identifying the user. Firebase auth also manages the user session so it keeps the user logged in after the application or browser restarts.
Example –
Create a new user with email and password:
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // ... });
Sign in an existing user with an email address and password:
firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; // ... });
Cloud Function
Cloud function is a lightweight, event based compute solution that allows you to create small, single-purpose functions that respond to events without the need to manage a server or a runtime environment. You can use Cloud Functions for Firebase if you’re a developer building a mobile app or mobile web app.
Features
- No server management.
- Scales automatically.
- Run the code in response to events.
- Connects and extends services.
What can be built with Cloud Functions
- Serverless application backends(eg. Serverless mobile backends, Serverless IoT backends, etc)
- Real-time data processing Systems(eg. Real Time stream processing, Event-driven extract, etc)
- Intelligent applications(eg. Virtual assistant and chatbots, Video and image analysis, etc)
Cloud Storage
The storage API lets users upload their files to the cloud, so they can be shared with anyone. If you want to set particular rules for sharing files with certain users, you can do this by firebase authentication. All data are transferred over a secure connection and also the transfers with the API are robust. It will automatically resume in case the connection is broken. This is essential for transferring large files over slow or unreliable mobile connections. As the firebase storage is backed by Google cloud storage, it can scale to petabytes. Also, it is available for iOS, Android and web.