Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Firebase Cookbook

You're reading from  Firebase Cookbook

Product type Book
Published in Nov 2017
Publisher Packt
ISBN-13 9781788296335
Pages 288 pages
Edition 1st Edition
Languages
Author (1):
Houssem Yahiaoui Houssem Yahiaoui
Profile icon Houssem Yahiaoui

Table of Contents (15) Chapters

Preface 1. Firebase - Getting Started 2. Firebase Real-Time Database 3. File Management with Firebase Storage 4. Firebase Authentication 5. Securing Application Flow with Firebase Rules 6. Progressive Applications Powered by Firebase 7. Firebase Admin SDK 8. Extend Firebase with Cloud Functions 9. We’re Done, Let’s Deploy 10. Integrating Firebase with NativeScript 11. Integrating Firebase with Android/iOS Natively 12. Hack Application's Growth 13. Adding Analytics and Maximizing Earnings 14. Firebase Cloud FireStore

Firebase Admin SDK

In this chapter, we'll cover the following recipes:

  • Integrating the Firebase Admin SDK
  • Implementing user account management by fetching users
  • Implementing user account management by creating accounts
  • Implementing user account management by deleting accounts
  • Implementing notification sending

Introduction

The Firebase Admin SDK provides more power than the existing power you have by offering privileged access to a different section in your console. From sending a notification to having the power to manipulate the user accounts, it also manipulates the Realtime Database and manages security via token generation and verification. It's the most suitable solution for application admin dashboards that can be applicable today.

This SDK is available in different ecosystems from NodeJS to Java and also over Python, with different implementation levels. The knowledge of using NodeJS can give us ultimate access to all the supported functionalities, which is not the case for other ecosystems. That's exactly what we'll work with; we'll use the Firebase Admin SDK in NodeJS context.

In this chapter, we'll see how we can manage our way through the SDK and...

Integrating the Firebase Admin SDK

Within this recipe, we're going to cover how to integrate Firebase Admin SDK with our project. The steps are intuitive and quite simple as any other integration within Firebase, so let's get to it.

Getting ready

Since we'll use the Firebase Admin SDK NodeJS client, we need to ensure that NodeJS is present in our development system, so first head directly to nodejs.org/download and download the suitable version for your system.

How to do it...

After doing so, let's ensure that we have NodeJS present in our system...

Implementing user account management by fetching users

The Admin SDK is present to provide one of the advanced features of Firebase within the same scope and perspective of better handling and better experience. Managing user accounts will include functionalities such as creating/deleting users, fetching users by email ID or phone number, updating users account properties, and accessing metadata.

In this recipe, we'll see how we can fetch users using nothing but the Firebase Admin NodeJS library. So, let's get busy!

How to do it...

Fetching users is the most common feature that any platform would want to feature, so let's see how we can fetch users from their email and phone number.

We will first learn about...

Implementing user account management by creating accounts

Using nothing but the Firebase SDK, we can create new accounts with some metadata directly from our dashboard so let's see how we can make that happen.

Getting ready

To perform such an operation, you will probably need to have a form; such a form will have many fields, including, but not exclusively, the email, password, name, and more. Such a form will perform a post request in order to send the data from our frontend to our backend, also known as API. Now over in our API, let's create a new route and add the custom logic that will eventually handle such a request.

...

Implementing user account management by deleting accounts

In order to delete an account, the Firebase Admin SDK will require you to have the user UID; such an ID can be grabbed in different ways, but one of the functionalities we have seen is for users to delete their own account, so this utility can be helpful. Let's see how we can make it happen.

Getting ready

In the user dashboard or settings pages, we want users to have a button to delete their accounts; this will launch a post request to our backend, calling the API to delete the account. This final should be secure enough to host such a functionality.

How to do it.....

Implementing notification sending

In Chapter 6, Progressive Applications powered by Firebase, we introduced how we can integrate the old FCM utility within our NodeJS server. Now the Firebase SDK provides us with more diverse methods to send push notification messages; plus, it plays nicely with other services, so let's see how we can send push notifications directly to our users using nothing but the Firebase Admin SDK.

How to do it...

In order to send push notification messages to users, we need to have their registration_token; such a token is grabbed from the user browser side, whether it's mobile or desktop. Google Chrome and Mozilla Firefox support this functionality, and at the time of writing this book, Safari...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Firebase Cookbook
Published in: Nov 2017 Publisher: Packt ISBN-13: 9781788296335
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}