31,19 €
Do you feel tired just thinking or even hearing about backend technologies, authentication or the tedious task of deployment? Firebase is here to change the way you develop and make your app a first-class citizen of the cloud.
This books takes a solution based approach by providing you recipes that would help you understand the features of Firebase and implement them in your existing web or mobile applications.
We start-off by creating our first Firebase application and integrating its services into different platforms and environments for mobile as well as web applications. Then we deep dive into Real-time Database and Firebase Storage that allows your users to access data across various devices with realtive ease. With each chapter you will gradually create the building blocks of your application from securing your data with Firebase Rules to authenticating your users with O-Auth.
Moving along we would explore modern application development techniques such as creating serverless applications with Firebase Cloud Functions or turning your traditional applications into progressive apps with Service workers.
Finally you will learn how to create cross-platform mobile apps, integrate Firebase in native platforms, and learn how to monetize your mobile applications using Admob for Android and iOS.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 238
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2017
Production reference: 1281117
ISBN 978-1-78829-633-5
www.packtpub.com
Author
Houssem Yahiaoui
Copy Editor
Safis Editing
Reviewer
Thomas David Kehoe
Project Coordinator
Devanshi Doshi
Commissioning Editor
Kunal Chaudhari
Proofreader
Safis Editing
Acquisition Editor
Larissa Pinto
Indexer
Francy Puthiry
ContentDevelopmentEditor
Aditi Gour
Graphics
Jason Monteiro
Technical Editor
Sushmeeta Jena
Production Coordinator
Deepika Naik
Houssem Yahiaoui, a backend engineer at Xapo from Algeria, has almost 4 years, experience in building everything from backend services to mobile apps using Hybrid, Not so Hybrid and Native Approaches. Houssem is also a Telerik Developer Expert title holder and community power believer. He's also a Google Developer Group Lead Organizer, Algeria Tech Community (Community Manager), and speaker at numerous national and international events from DevFests to DroidCon, sharing his experience of web technologies, and a love for serverless approaches and Firebase.
Thomas David Kehoe makes technology for speech clinics to treat stuttering and other speech disorders. He is interested in how auditory processing affects second language acquisition. He develops web apps using Firebase, Angular, and JavaScript.
For support files and downloads related to your book, please visit www.PacktPub.com. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.comand as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at www.amazon.in/dp/1788296338.
If you'd like to join our team of regular reviewers, you can email us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
Introduction
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Firebase - Getting Started
Introduction
Creating your first Firebase application
How to do it...
Adding Firebase to an existing frontend project
How to do it...
How it works...
Integrating Firebase into the backend
How to do it...
How it works...
Integrating Firebase in Android applications
Getting ready
How to do it...
Integrating Firebase in iOS applications
Getting ready
How to do it...
Firebase Real-Time Database
Introduction
Saving and serving data in and from our Realtime Database
How to do it...
How it works...
Updating and deleting data from our Realtime Database
How to do it...
How it works...
Structuring data within our Realtime Database
How to do it...
Implementing offline capabilities support
Getting ready
How to do it...
How it works...
File Management with Firebase Storage
Introduction
Creating file storage references
Getting ready
How to do it...
How it works...
Implementing file upload
How to do it...
How it works...
Implementing file serving and downloading
How to do it...
How it works...
Implementing file deletion
How to do it...
Implementing file metadata updates
How to do it...
Firebase file storage error handling
How to do it...
Firebase Authentication
Introduction
Implementing email/password authentication
How to do it...
Implementing anonymous authentication
How to do it...
Implementing Facebook login
Getting ready
How to do it...
Implementing Twitter login
Getting ready
How to do it...
Implementing Google Sign-in
Getting ready
How to do it...
How it works...
Implementing user metadata retrieval
How to do it...
How it works...
Implementing the linking of multiple authentication providers
How to do it...
How it works...
Securing Application Flow with Firebase Rules
Introduction
Configuring the Firebase Bolt language compiler
Configuring database data security rules
Getting ready
How to do it...
How it works...
Configuring database user data security rules
Getting ready
How to do it...
How it works...
Configuring storage files security rules
Getting ready
How to do it...
How it works...
Configuring user storage files security rules
Getting ready
How to do it...
How it works...
Progressive Applications Powered by Firebase
Introduction
Integrating Node-FCM in a NodeJS server
How to do it...
Implementing service workers
How to do it...
How it works...
Implementing sending/receiving registration using Socket.IO
How to do it...
How it works...
Implementing sending/receiving registration using post requests
How to do it...
How it works...
Receiving web push notification messages
How to do it...
How it works...
Implementing custom notification messages
How to do it...
How it works...
Firebase Admin SDK
Introduction
Integrating the Firebase Admin SDK
Getting ready
How to do it...
Implementing user account management by fetching users
How to do it...
Implementing user account management by creating accounts
Getting ready
How to do it...
Implementing user account management by deleting accounts
Getting ready
How to do it...
How it works...
Implementing notification sending
How to do it...
How it works...
Extend Firebase with Cloud Functions
Introduction
Getting started with Cloud Functions
Getting ready
How to do it...
Implementing data manipulation
Getting ready
How to do it...
How it works...
Implementing data-change monitoring
Getting ready
How to do it...
How it works...
Welcoming users upon account creation
Getting ready
How to do it...
How it works...
Implementing account email confirmation
Getting ready
How to do it...
How it works...
Sending re-engagement emails to inactive Firebase users
Getting ready
How to do it...
How it works...
We’re Done, Let’s Deploy
Introduction
Deploying our application to Firebase
Getting ready
How to do it...
How it works...
Customizing the Firebase hosting environment
How to do it...
How it works...
Integrating Firebase with NativeScript
Introduction
Starting a NativeScript project
How to do it...
Adding the Firebase plugin to our application
How to do it...
Pushing/retrieving data from the Firebase Realtime Database
Getting ready
How to do it...
How it works...
Authenticating using anonymous or password authentication
Getting ready
How to do it...
How it works...
Authenticating using Google Sign-In
Getting ready
How to do it...
How it works...
Adding dynamic behavior using Firebase Remote Config
Getting ready
How to do it...
How it works...
Integrating Firebase with Android/iOS Natively
Introduction
Implementing the pushing and retrieving of data from Firebase Realtime Database
How to do it...
Implementing anonymous authentication
How to do it...
How it works...
Implementing password authentication on iOS
How to do it...
How it works ...
Implementing password authentication on Android
Getting ready
How to do it...
How it works...
Implementing Google Sign-in authentication
Getting ready...
How to do it...
How it works...
Implementing Facebook login authentication
Getting ready...
Facebook authentication in Android
Getting ready...
How to do it...
How it works
Facebook authentication in iOS
Getting ready
How to do it...
How it works...
Generating a crash report using Firebase Crash Report
How to do it...
Adding dynamic behavior using Firebase Remote Config in Android
Getting ready
How to do it...
How it works...
Adding dynamic behavior using Firebase Remote Config in iOS
Getting ready
How to do it...
How it works...
Hack Application's Growth
Introduction
Implementing sending/receiving app invite in Android/iOS
Getting ready
How to do it...
How it works...
Implementing topic subscription in Android/ iOS
How to do it...
How it works...
Adding Analytics and Maximizing Earnings
Introduction
Integrating Firebase analytics into Android/iOS applications
How to do it...
Implementing event logging on Android/iOS
How to do it...
Implementing user properties for data and audience filtering
How to do it...
Integrating Firebase AdMob with Android/iOS applications
How to do it...
Implementing Firebase AdMob banner ads on Android/iOS
Getting ready
How to do it...
How it works...
Implementing Firebase AdMob native ads express on Android/iOS
Getting ready
How to do it...
How it works...
Implementing AdMob ads targeting
Getting ready
How to do it...
How it works...
Firebase Cloud FireStore
Whether we like it or not, the world is moving toward different development schemes in ways that technically differ from one team to another or even from one developer to another. As a backend developer, I understand the hustle, from having a really dependable database to implementing an effective authentication system that can be relied on to keep things secure, without forgetting about the authorization part, where you simply manage the part of who has access to what.
Such a hustle is not even the beginning; in a mobile-first world, improving your users' mobile application functionalities is a critical task because you will always need to improve your application security, maintain a notification system that scales, and have a great user interface and experience, but even with all this, you will the analytics, revenue generation part which is still essential, because you simply want to listen to your users' needs and breaking point within your application in easy seamless way without too much pain.
Firebase provides all of that and much more in a set of interconnected products that simply lets your application have everything that Firebase has to offer. This book will go through each topic over the 13 chapters divided into problem/solution recipes. All the points covered here come from real-world scenarios that each and every new or old application might have faced or will face within its development workflow.
Chapter 1, Firebase - Getting Started, begins with the process of integrating Firebase and its services into different platforms and environments, from frontend and backend projects to Android/iOS projects.
Chapter 2, Firebase Real-Time Database, introduces one of the most used features of Firebase—Firebase Real Time. It covers how to implement the daily input entering and retrieval and update of your data; it also covers how we can structure our data better and finishes by enabling all these features and enabling them offline.
Chapter 3,File Management with Firebase Storage, explains how we can upload, download, and manage files within our Firebase Storage.
Chapter 4,Firebase Authentication, presents the different ways in which you can authenticate your users using Firebase, from traditional authentication to an OAuth-based login process that is different from Facebook, Google, and Twitter.
Chapter 5,Securing Application Flow with Firebase Rules, explains how to secure Firebase Database and Firebase Storage using the powerful Firebase authorization rules.
Chapter 6,Progressive Applications Powered by Firebase, shows how to turn a boring application with old features into a progressive one using service workers and Firebase.
Chapter 7,Firebase Admin SDK, describes how we can create a basic dashboard and interact with other Firebase functionalities from the diverse set with more authorization and a more powerful API to manage users and notifications.
Chapter 8,Extend Firebase with Cloud Functions, covers how we can use Firebase Cloud Functions and integrate it and interact with different Firebase products to extend its functionalities and go literally serverless ending up with deployment interactivity within the Firebase console.
Chapter 9,We're Done, Let's Deploy, is about deploying your code to the Firebase Static hosting and making some config-based customizations to the user experience.
Chapter 10, Integrating Firebase withNativeScript, shows the proper way to use Firebase within the NativeScript a lot of platforms applications.
Chapter 11, Integrating Firebase with Android/iOS Natively, is all about implementing Firebase features from Interacting with the Realtime Database to authentication in native context for Android and iOS applications.
Chapter 12, Hack Application's Growth, dives into the little functionalities that simply generate more leads and improve the application's user experience, covering app invites and topic-based notifications.
Chapter 13, Adding Analytics and Maximizing Earnings, shows how you can integrate analytics and incorporate AdMob so that you can generate revenue from different ad types.
Appendix, Firebase Cloud FireStore, talks about the power points of Firebase Cloud Firestore and its differences from earlier model.
The content requirements are fairly easy for the first 10 chapters; no matter what your operating system or your code editor is, you're always covered.
However, in Chapter 11, Integrating Firebase with Android/iOS Natively, we'll start developing for mobile, so while you will be perfectly fine with any operating system (macOs, Linux, or Windows) when developing for Android, we will definitely need a macOS-based computer in order to follow along with iOS-based recipes.
This book is for anyone who wants to use Firebase for their personal/professional projects. As this book covers multiple platforms and different development environments, there's everything for everyone.
The need for this book will simply come from the willingness to know the interesting parts that makes Firebase an interconnected set of tools that simply makes developers' lives much easier by demystifying the hustle that developers usually come across while creating projects from scratch or just implementing new features. So technically, like I mentioned, there's everything for everyone.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title on the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your email address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Firebase-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/FirebaseCookbook_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
In this chapter, we will cover the following recipes:
Creating your first Firebase app
Adding Firebase to an existing frontend project
Integrating Firebase in the backend
Integrating Firebase in Android applications
Integrating Firebase in iOS applications
With the changing web and mobile scene, finding a suitable solution and technology that suits these climbing, fast needs is a must. From web development to mobile, the way we treat APIs, data, and security, and how we make users feel as engaged as we possibly can, is an urgent matter.
Going from a traditional setup to the cloud leads to many new patterns and architectures. Backend-as-a-service (BaaS), saves us from tons of useless setup and configuration and makes us think of nothing but our application logic.
Here we are introducing Firebase, a feature-heavy BaaS that will make creating your next awesome project a breeze. It will eliminate many tedious tasks and even manpower and will create your server-side code and give you a more secure, well-built platform that will completely change your thoughts about simplicity and scalability.
So, hold on tight and let's start our journey together by creating our first ever Firebase application.
The process of creating a Firebase application is straightforward and mainly visual. This recipe will demonstrate the process of creating a Firebase application from scratch.
As mentioned previously, we will use nothing but our clicking superpower and our favorite browser. First, head directly to the Firebase official website:
https://firebase.google.com/
. A screenshot of the website page is as follows (
Figure 1
):
Now, go to the top navigation bar and click on the
SIGN IN
button. This will lead to another page where you will be introduced to the Google authentication page showcased in the following figure, where you can select the most suitable account for your development work (
Figure 2
):
Now, after you select the most suitable Google account, you will find yourself redirected to this link:
https://console.firebase.google.com/
. You will find all of your Firebase projects here, and you can introduce new projects as well (
Figure 3
):
Now, we do have two options: whether to import a Google project or simply start a fresh one. Let us learn how to start a new project.
After clicking on the
Add project
plus button, you will be introduced to a model where you can add the
Project name
and
Country/region
. Keep in mind that the
Project name
and
Country
are variables, so you can change their values to the values that suit you best. You can see the page for creating the project in the following screenshot (
Figure 4
):
After finishing the previous step, you will be redirected to your Firebase dashboard (
Figure 5
):
Congratulations! You've successfully created your first Firebase project. You have seen that the steps are really simple and are applicable to any Firebase project that you may create now or in the future.
Since Firebase is indeed a backend platform which typically acts as a service, it's not strange to see today's developer ditch the idea of creating a backend in general. They just focus on their frontend, which is actually the main idea behind serverless architecture nowadays.
In the previous steps, we integrated the Firebase JavaScript client over our web page, and we also created the basic backbone configuration. Following the documentation guidelines, we copied/pasted the configuration script that would hold all the required tokens and API keys that Firebase was going to need in order to support our functionalities.
Firebase is already a complete solution that can simply replace our backend, but sometimes, due to some requirements, you will find yourself integrating Firebase into the already present backend.
In this integration process, we will integrate Firebase services in a NodeJS backend application.
Similar to the frontend integration, in our backend we are doing the following:
Using a node package manager or npm to install the Firebase
commonJS
library, where we will find all the necessary APIs.
We're requiring/importing Firebase to be part our application, passing it to the configuration object that will hold all our API keys, links, and more.
Lastly, we're initializing our application with the configuration object we just created.
