The Firebase Session component
Manage a user session (logged in/out) and associate data with your users (score, progress, account type, etc.) using Firebase. This component must be associated with the Authentication component, which represents the visual part of the authentication process.
In this article
Enable Firebase Authentication
Firebase is Google's mobile platform that enables the creation of a scalable and high-performance backend, primarily dedicated to mobile applications. The backend represents the server side of the application, handling responsibilities such as authentication, storage, notifications, etc.
💡 You need to have created a Firebase project for your application. Follow this tutorial to create a new project, then follow the instructions below.
Enable Email/Password Login
Add an authentication method for your application.
- Go to Authentication and click on Get Started.
- In the Sign-in method tab, select Email/Password and click Enable.
You now have an email and password authentication procedure.
Configure Cloud Firestore
Cloud Firestore is a database specific to Firebase. It allows you to associate data with your users.
- Go to the Firestore Database tab. Click on Create Database.
- Choose the Start in test mode option.
- Go to the Rules tab: you need to update the security rules to avoid being 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 } } }
Your Cloud Firestore configuration is ready.
Insert the Firebase Session Component
Click on Components and choose Firebase Session. 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.
These details are available in the Project Settings on Firebase.
Force Authentication After (hours)
This option specifies the number of hours (after identification) during which 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 log in again. By default, a value of 0 creates an infinite session.
💡 Don't forget to insert the Authentication component to display the login form in your application.
Trigger an Action Based on User's Connection Status
To trigger an action based on the session state, select the Firebase Session component and add an action. Choose from the following trigger events:
- User connected: the user session is valid. This trigger allows, for example, to proceed to the next screen if the user is connected.
- User disconnected: the user session has expired. It allows you to redirect the user to the authentication screen.
You can also log out the user: Interact with a component > Firebase Session > Log out.
Manage Your Users
You can manage your users directly on Firebase.
Go to Authentication and in the Users tab to find your user base. You have access to the following data: email, creation date, last login date, and unique user ID (user ID).
You can manually add one or more users.
💡 You can also associate data with your users: a score, a level of progress, a profile... Define this data in PandaSuite Studio and find it in your Cloud Firestore database. Learn more: Save User Data via Firebase