Getting data from Firestore
To be able to connect to Firestore from Bravo, we'll need to implement user authentication with Firebase on our app. When a user logs in, an authentication token will be created, and this will allow us to target the Firestore REST API and use it as database for our app (more on this in the next section).
To set this up, we'll need to follow the steps described in the documentation below:
Once we have our Firebase authentication in place, we can create some users, either in the Firebase project itself, or by creating a register screen in the app and creating users there.
After having some users in Firebase, we can start creating our API collection to target Firestore. If you haven't created a Firestore collection yet, you can do that in the
Firestore Databasesection of the Firebase console.
Once we have the Firebase project in place, and we have set up Firebase login in our app project, we can start creating our API collection.
Firestore requires authenticated requests to be able to communicate with its REST API. This means the API requests will contain an auth token from an existing user in our Firebase project. This token will be validated in Firestore when performing an API request.
Therefore, we'll specify an authentication method in our API collection. Once you have created a new collection, go to Collection Settings, and specify the Bearer authentication mode (leaving the token field empty).
Once we do this, we'll be able to create API requests targeting the Firestore collections.
The next step will be creating a sign in request. Although we won't bind this request to any app screen, we'll need it to obtain an authentication token and send authenticated requests against the Firestore API.
[API_KEY]with the value of the Web API Key of our Firebase project. We can obtain it in the Project Settings section of our project, in the Firebase dashboard.
This will be a
POSTrequest. We'll need to add the following body to it:
Now, we'll be able to test the request by indicating the credentials (email and password) of an existing user in our project. If the request is successful, we'll get back a set of values, including our authentication token (
Now that we can get valid authentication tokens, we'll be able to interact with our Firestore collections.