Firebase Plugin

Add Google's Firebase for user authentication and access to the Firebase Realtime Database.

Firebase Realtime Database

Store and retrieve user-specific data from the Firebase Realtime Database. Data is synced across all clients in realtime, and remains available when your app goes offline.

Firebase Storage Cloud

Upload binary files to the Firebase Storage Cloud. Uploaded files are then available at a public HTTPS URL.

Firebase User Authentication

Allow your app to know the identity of a user, securely save user data in the cloud and provide the same personalized experience across all of the user's devices.

Overview

The Firebase plugin allows using the Firebase backend services. FirebaseAuth provides e-mail authentication to create user accounts, log in and log out. You can access the FirebaseDatabase and store and retrieve user-specific data with and without authentication. Use FirebaseStorage to upload binary files to the
cloud.

Use Cases

User Authentication

Most apps need to know the identity of a user. Knowing a user's identity allows an app to securely save user data in the cloud and provide the same personalized experience across all of the user's devices.

Firebase Authentication provides backend services to authenticate users to your app. The plugin currently supports anonymous authentication and authentication using e-mail and password.

Users can log in anonymously to start using your app without creating an account. For this, you can call FirebaseAuth::loginUserAnonymously(). This method
creates a new temporary anonymous user account. The user can then enter their e-mail and password at a later time. This way, they can link the anonymous account to their credentials to use their data from any device.

Use FirebaseAuth::registerUser() for e-mail and password authentication. This creates a new account with e-mail and password if the user is not yet logged in. If the
user is already logged in anonymously, it links the anonymous account with the provided credentials.

Note: Anonymous accounts are temporary. If the user logs out before providing their credentials, any user-data on this account is lost.

Additionally, Firebase comes with a "forgot password" feature out of the box, which you can easily use in your application without tedious setup. Call FirebaseAuth::sendPasswordResetEmail() to send an e-mail with recovery information to a provided address.

Note: You can enable each authentication method you would like to use in your app in the Firebase backend console. E-mail authentication is enabled by default. To use anonymous accounts, you can enable the sign-in
method under Authentication -> Sign-in method:

Support for popular federated identity providers like Google, Facebook and Twitter can be added to the plugin on request. Please contact us for more information.

You can design the login screen completely customized for your app. If you don't want to do that, we've got you covered as well: You can easily create a login page template using our wizard. Just click File -> New
File or Project -> Felgo Apps -> Page and in the next step, select Login Page as Page Type.

Realtime Database

Store and sync data with the Firebase NoSQL cloud database. Data is synced across all clients in realtime, and remains available when your app goes offline.

The Firebase Realtime Database is a cloud-hosted database. Data is stored as JSON and internally synchronized in realtime to every connected client.

When you build cross-platform apps with the Realtime Database, all of your clients share one Realtime Database instance. The Firebase backend automatically receives updates with the newest data as soon as the database is
changed by one of the clients. Additionally, changes to the database are propagated to other clients and can be read by the clients in real time.

The Firebase database stores data in JSON format. Firebase and the Felgo Plugin support the primitive data types string, number and boolean. You can structure data using nested objects
and arrays.

Retrieve data using a path into the JSON tree. For example, if your database looks like the one in the picture, calling firebaseDb.getValue("public/news") obtains the string "Firebase Plugin is now
live".

Additionally, you can query data using an optional second parameter to FirebaseDatabase::getValue(). The parameter is a JSON object specifying which kinds of queries
to use. This way, you can filter objects by their keys and values or limit the number of keys to obtain in an object.

For example, the following code obtains the database object at the path "public/bigqueryobject". The query returns only keys alphabetically between "c" and "m" and limits the object to
contain at most 5 keys.

Realtime Database vs. Felgo WebStorage

Felgo also comes with its own easy to use WebStorage, which connects to the Felgo backend. It is a simple key-value store which syncs across different devices and platforms via the
Felgo Game Network Backend as a Service (BaaS).

All platforms: Felgo WebStorage works not only on iOS & Android but on all supported Felgo platforms. This also includes Desktop and embedded systems.

No authentication required: With Felgo WebStorage, you can access per-user data without your users having to log in.

Late authentication: Your users can authenticate later but start saving user data before this authentication. Once they do authenticate, their data is kept and merged to the new user profile.

Advanced merge conflict management: With Felgo WebStorage, you can modify the default merge conflict rules that may occur if your user stores to the same key from multiple devices at
the same time. In Firebase, the last write is used, whereas in Felgo a merging of the data is tried first. Additionally, you can customize the merge behavior to your requirements with the WebStorage::dataConflictStrategy property.

These are the same features like Firebase has:

Offline usage: You can write and read values from the storage even if the user is offline. As soon as the user has Internet Connection again, the locally cached data is synchronized with the cloud.

Data synchronization: If the same user is authenticated on multiple devices, a change in the data is forwarded to all connected devices in realtime. This way, the user has the same data across all devices, even across
platforms.

There is one restriction with WebStorage though: user access rights. With Felgo WebStorage, there are 2 access rules: per-app and per-user data. The
per-user data cannot be shared with other users, and the per-app data cannot restrict its access to certain users. You can work around this restriction by adding custom fields to your per-app data that specifies to which user
the app-wide data shall be available for. However, if you have advanced requirements for user rights & data management, the Firebase Realtime Database is the better solution as you can define access rules comprehensively.

For a quick summary: if you are only looking for a simple key-value store in the cloud that gets synced to multiple devices, you are better off with the Felgo WebStorage.

Firebase Storage Cloud

Firebase Storage hosts a virtual file system where you can upload any binary files. You can then download them from anywhere using a public URI.

You can upload binary files using the FirebaseStorage QML item. After the upload, you retrieve a public HTTPS URL where the file is available. You can use these cloud URLs from
anywhere.

For example, this lets you allow your users to upload a profile picture from the device or the camera. You can take pictures with NativeUtils::displayCameraPicker(). You can select local pictures with NativeUtils::displayImagePicker().
Afterwards, you can upload the image file and display it on this user's profile.

Plugin Demo App

Example Usage

The Firebase items can be used like any other QML item. Here are two simple and one more advanced example of how to integrate the plugin into your Felgo app or game.

These examples show off some of the use-cases of the Firebase plugin. The first and second examples demonstrate the authentication and database functions. The third example is more advanced and shows how to use the FirebaseAuth and FirebaseDatabase items in combination to store user-specific values in the database. It also shows how to use the built-in
password-reset mechanism.

Firebase Authentication Simple Example

This is a very simple e-mail login example with FirebaseAuth. It uses a public database, so the test e-mail of this example will already be registered at the time you test it. You can
change the e-mail in this example to test the registration as well.

Firebase Authentication Advanced Example

This example uses FirebaseAuth to authenticate users. The user has the option to log in with e-mail and password or anonymously. When logged in anonymously, they can link their e-mail
and password later.

When the user is authenticated, FirebaseAuth::authenticated is true. You can then use FirebaseAuth::userId to
identify this user. When the user is logged in with the same e-mail and password, this user ID will be the same on each device.

The other parts of the Firebase plugin also automatically work with authentication. With FirebaseDatabase, you can access private user data when authenticated. FirebaseStorage can use authentication to restrict access to uploaded files to specific users.

Firebase Database Filtering Example

This example shows how to query only parts of the data with the FirebaseDatabase item. Using the queryProperties parameter to FirebaseDatabase::getValue(), only the newest 20 items of the database, ordered by timestamps, are returned. A click on a button creates a new item with the current time as
timestamp.

Multiple Firebase Accounts Example

It is also possible to use more than one Firebase account in a single app. Use the QML type FirebaseConfig to specify custom Firebase account details and override the default account
specified with google-services.json and GoogleService-info.plist.

Firebase Authorization and Private Database Example

This example demonstrates advanced usage of the Firebase plugin. The users can authenticate themselves via a simple login form. When authorized, private per-user values are stored to and retrieved from the database.
Additionally, it shows how to use the "Forgot Password" functionality of Firebase.

Item allows to read and write user-specific and public data from and to the Firebase Realtime Database. Data is synced across all clients in realtime, and remains available when your app goes offline. As soon as the
user goes online again, the changes are synced up to the Firebase cloud backend

Adding and Activating Plugins

How to Add a Felgo Plugin to your App or Game

When you create a new project, you can choose to add example plugin integrations as well. Open Qt Creator and choose “File / New File or Project”, then choose Single-Page Application in the Felgo Apps section or any
other wizard. For Felgo Games, you can also find an own Game with Plugins project template as an own wizard.

Then select the platforms you want to run your application on. The plugins are available for both iOS & Android. There is a fallback functionality in place on Desktop platforms so your project still works when you call
methods of the plugins. This allows you to do the main development on your PC, and for testing the plugin functionality you can run the project on iOS and Android.

After the Kit Selection, you can choose which of the plugins you’d like to add to your project:

Then complete the wizard, your project is now set up with all the correct plugin dependencies for Android & iOS automatically. This includes:

Setting up the .gradle file for Android.

Setting up the .plist file for iOS.

Setting up the .pro file to include the plugin libraries for iOS.

Note: Additional integration steps are still required for most plugins, for example to add the actual plugin libraries for iOS to your project. Please have a look at the integration steps described in the
documentation for each of the used plugins.

If you have an existing Felgo application, follow these steps to include a plugin to your app or game:

In Qt Creator, select “File / New File or Project” and choose either Felgo Games or Felgo Apps from Files and Classes. Then select Felgo Plugin and press Choose.

You can now select the plugin you want to add:

The plugin item, which contains the chosen plugin and a short usage example, is now added to your project. To use the item in your project, simply perform these steps:

Include the created item (use the name you entered in the template before) in your main.qml file.

Modify the .pro file & .plist file for iOS usage. See the iOS integration guide of the chosen plugin for more information.

Modify the the .gradle file for Android usage. See the Android integration guide of the chosen plugin for more information.

Note: If you have an existing Qt application, you can also add Felgo Plugins to your app! See here
how to do this.

Activating Plugins with a License Key

You can test all plugins as soon as the required integration steps and plugin configuration are completed.

However, the plugins are only available as Trial Versions if they are not activated with a valid license. When you are using unlicensed plugins, a dialog is shown and a watermark overlays your application to notify you about
the testing state of the plugin.

All monetization plugins are free to use in all licenses, other plugins are only fully usable if you have purchased the Indie or Enterprise license. To activate plugins and enable
their full functionality it is required to create a license key. You can create such a key for your application using the license creation page.

This is how it works:

Choose the plugins you want to include in your license key:

Click on “Generate License Key” and set the app identifier & version code of your application. You can see that the AdMob plugin was enabled in this license key:

These rules grant everyone access to all child nodes of the public branch. In addition, with these rules, an authenticated user can access data that is stored in the users/<individual-user-id>
branch of the database.

To learn more on Database Rules, we recommend to read up on the topic in the Firebase Docs.

Used Firebase SDK Versions

iOS

4.13.0

Android

15.0.0

Note: Other SDK versions higher than the stated ones might also be working but are not actively tested as of now.