Configuring DB connectors - Firebase Auth (user management)

Studio enables you to use the database connectors to connect to your databases like Elasticsearch, MongoDB, CouchDB, DynamoDB, Cloud DataStore, Firebase, and so on.

Firebase is a highly durable database that can scale automatically to handle your application’s load.

The Studio has a subcategory API of Firebase called User Management. The Firebase Auth for User Management provides for managing your Firebase Authentication users with elevated privileges. This user management connector gives you the ability to programmatically complete several tasks such as creating users, looking up for users, listing all users, and more, from a secure server environment.

Prerequisite

You need to first configure the database. Enter the Connector name which would be used when you need the connector in your apps and while adding queries. To connect a Firebase Connector you need to get the configuration details from the Firebase console.

Under the Firebase console, click on your Project settings, and choose the Service accounts tab. Select the Firebase Admin SDK icon, and click Generate new private key. A JSON file is then downloaded from where you can copy the Private key and paste it into the Firebase Connector.

Optionally you can also create an account key from your Google Cloud Platform console. Select a project, and click Create Service Account and assign the “role” as Firebase Admin. Create a JSON Key type and download the file. Keep it handy for use for connector configuration.

Configuring the Firebase Auth (User Management) connector

To add a third-party DB connector, under Studio > Connectors, click (+) Connector. Select Firebase Auth (User Management) connector.


Enter the Connector name.

Copy the URL from the Firebase Console > Realtime Database > Data. It is typically in the form of https://.firebaseio.com/

Copy it to the Connector configuration Firebase Database URL and the Private Key from the JSON File that you had downloaded.

Once these configurations are added, click Test Connection. If the authentication is successful you would get the response accordingly.

Click Save to Finish configuration.

Adding queries to Firebase Auth (User Management) connector

Now that you have configured the connector you will find it under the Custom Database connectors list. Further to fetch data or undertake any other action, click the Add query option available after your connection is ready.

Here you can add your queries by simply clicking add query.

So click Add Query and create a query. Enter a Query name and select your query Action and click Run or press Ctrl + enter to run the query. The rows returned from the database are shown in the Response section.

You can also add dynamic values using the Variables. To use a variable inside a query, you simply need to put it into double Curly brackets. The Test value that you entered would be considered for fetching data. When using the connector queries the dynamic variables would have to be linked to the respective control for further run-time functioning.

Using queries of Firebase Auth (User Management) connector

When you add a query with respect to the connector of Firebase Auth (user management), in the query builder you will find a dropdown of Action with all sorts of queries you can perform and add to the connector.

List Users

Let’s choose List Users, it helps you to list all the users of a specified project of a batch. Each batch of results contains a list of users and other details such as UID, tokens and more.

In the query builder you can provide details to put limit on number of users to be fetched. By default, it fetches 1000 users per batch if the limit is not provided.

If you have several pages of data of users, and you want to start the list of users from a certain page then you need to provide a page token, or else it will return users starting without any offset. These values can also be provided dynamically by creating variables of limit and offset.

You can read more about this here.

To display data or work with the data, you can now bind this subcategory of the connector to different controls, actions, and more.
For this I will be using table grid to view the details of the users, also with table grid properties, we can provide offset and limit data very easily.

Go to Bind Data> Connectors and configure the query.

Get User By UID

The very primary way to identify a user is by their uid and this action uses the uid of a user and fetches all the details of that user.

You just need to provide the uid with the request and in response, you will receive all the details of the user, present in the system. To make it more flexible from microapp point of view, you can provide the UID as dynamic value by creating its variable.

To display data or work with the data, you can now bind this subcategory of the connector to different controls, actions, and more.

I will be using JSON viewer control to display the user details and input control to provide dynamic UID values for the connector to make requests.

Going to quickly add the connector from server-side action on the button, then set the response data in the JSON viewer. Configure the Connector Fields with Dynamic Variables passed as Parameter.

Preview the app and search for user by providing a valid UID.

Get User By Phone Number

You can also use the phone no. Of a user to fetch the details. You just need to provide the phone number with the request and in response, you will receive all the details of the user, present in the system.

This query can also be executed by making the phone number as dynamic value, so that user can provide input every time of their choice.

To display data or work with the data, you can now bind this subcategory of the connector to different controls, actions, and more.

Get User By Email

You can also use the email ID Of a user to fetch the details. You just need to provide the email address with the request and in response, you will receive all the details of the user, present in the system.

To make it more flexible from a microapp point of view, you can provide the email address as a dynamic value by creating its variable.

To display data or work with the data, you can now bind this subcategory of the connector to different controls, actions, and more.

Get User By Provided UID

Every detail of a user is stored as data along with a Firebase’s unique ID - UID, but sometimes, users login from different third-party websites into Firebase and this creates additional information which is stored in the user’s data itself but as provider data. This data consist of different information along with a providerData - UID.

This query will enable you to fetch details of a user by using the provider UID instead of Firebase’s UID. This query can also be executed by making the provider UID as a dynamic value, so that users can provide input every time of their choice.

To display data or work with the data, you can now bind this subcategory of the connector to different controls, actions, and more.

Create a User

The Studio query builder for Firebase Auth (user management) connector also supports an action to create a new user.

The Create a User action provides a method that allows you to create a new Firebase Authentication user. This method accepts an object containing the profile information or user properties, to include in the newly created user account.

While creating a new user, you can provide all the values and properties as dynamic so that user can pass all the details later on as parameters to the connector.

User Properties

{“email":"b@example.com”, “displayName”: “B”, “emailVerified”:true}

To feed the data you can connect this subcategory of the connector with different input controls.

Update a User

The Studio query builder for Firebase Auth (user management) connector also supports an action to update an existing user’s details.

The Update a User action provides a method that allows you to update details of an existing Firebase Authentication user. This method accepts uid of the existing user and an object containing the profile information or user properties, to update in the data of the user account.

While updating user details through referencing with UID, you can provide all the values as dynamic so that user can pass all the details later on as parameters to the connector.

Below, you can see that we are right now only focusing on updating the email address of a user via UID.

To provide details to make the call, you can use various input controls and actions. Later with controls you can showcase the end result of data after changes.

I will be using input field to get the UID and emails to pass it as keyword parameters and display the final response in JSON viewer.

Add the connector as server-side action on the button, then set the response data in the JSON viewer. Configure the Connector Fields with Dynamic Variables passed as Parameter.

Delete a User

Finally, with this last action, you can delete an existing user from the Firebase Auth users’ database. Provide the UID of the user, whose details you want to delete.

The delete user method returns a successful response for deleting as a result when the deletion completes successfully. If the provided uid does not correspond to an existing user or the user cannot be deleted for any other reason, the delete user method throws an error.

I will be using toast action to display the response and input control to provide dynamic UID values for the connector to make requests.

quickly add the connector from server-side action on the button, then provide a toast on successful deletion.

Configure the Connector Fields with Dynamic Variables passed as Parameter.

Now, preview the app and provide a valid UID of a user which is to be deleted.