Firebase Session

The Firebase Session component allows you to manage a user session (logged in/out) and associate data to your users (score, progress, account type...). It is necessarily associated with the Authentication component which represents the visual part of authentication.  

Firebase is Google's mobile platform that allows the creation of a scalable and powerful backend, dedicated mainly to mobile applications. The backend represents the server part of the application that manages responsibilities such as authentication, storage, notifications, etc...

In this article

Create a Firebase project

The Firebase Session component requires an account on Firebase, it's free depending to a certain volume ( details here). You can totally get started in a free setting.

To create an account, here is the link: https://console.firebase.google.com/

cre_er-un-projet-firebase.png

Choose a name for your project. You need to create one new project per application. 

choisir-un-nom-projet-firebase.png

Follow the steps and submit. 

e_tape-2-projet-firebase.png

Enable Email/Password Login

Go to Authentication and into the Sign-in method tab. 

Click on. Enable for the Email Address/Password option as shown below.

autoriser-email-mot-de-passe-firebase.png

You now have an authentication procedure. 

Configure Cloud Firestore

Cloud Firestore is a Firebase specific database to associate data with your users.

Go to the Database tab. Click Create Database.

cre_er-une-base-de-donne_es-firebase.png

Choose the mode  Start in test mode.

start-in-test-mode.png

nouvelle-database.png

Go to the tab  Rules: you need to update the security rules so that you are not blocked after 30 days. Copy and paste the code below:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth.uid == userId
    }
  }
}

mettre-a_-jour-re_gles.png

Your Cloud Firestore configuration is ready.


Insert the Firebase Session component

Click on Components and choose Session Firebase. To make the component accessible throughout the application, insert it at the project level.

In the properties, copy/paste the project ID and the API Key from the Firebase console:


This information can be accessed from the Project settings on Firebase.

parame_tres-du-projet-firebase.png

identifiants-projet-firebase.png

Force authentication after (hours) 

This option specifies the number of hours (after login) that the session remains valid, even without an internet connection. Beyond this number of hours, an internet connection will be required to continue. When the session is still valid, the user will not need to reconnect. By default, the value 0 creates an infinite session.

💡 Don't forget to insert the Authentication component to display the login form in your application. 


Trigger an action if the user is logged in or not

To trigger an action based on the session state, select the Firebase Session component and add an action. Choose from the trigger events: 

  • User signed in: the user session is valid. This trigger allows, for example, to go to the next screen if the user is logged in. 
  • User signed out: the user session has expired. It allows you for example to redirect the user to the authentication screen.

You can also disconnect the user: Interact with a component > Firebase session > Disconnect. 


Manage your users

You can manage your users directly on Firebase.

Go to  Authentication and into the Users tab to find your user base. You have access to the following data: email, creation date, last login date and their unique identifier (user ID). 

You can manually add one or more users. 


Associate data with user

You can also associate data with your users: a score, a progress level, a profile...

Define this data in PandaSuite Studio and find it in your Cloud Firestore database. You can reuse them to display a ranking, extract statistics ...

Associate a data

Simply create an action Modify the data on the Session Firebase component to associate this data with the user. If this data does not exist, it is created. Otherwise it is updated. 

Let's take the example of a score. Select the correct answer and add the action Interact with component > Firebase session > Modify the data. Create a score data and use the Increment function with the value 1. 

💡 Beware of wording and typos: you need to use the same name for this data wherever you use it. 

Get data

You can track the score of your users from Firebase.
Go to Firestore and the Data tab to find your users database. Each user is presented in the form of its unique identifier. You will find the Score field.

Display a data

You can display this data in your application:

Still need help? Contact Us Contact Us