Saving the user data to database (Firebase)

I have a question regarding saving the user data to the database (Firebase).
I have created some forms, for my app. And based on the selection of the user, the user is directed to the next page. I have used app variables and page parameters to pass the data. So now, after filling in all the user data, the user is moved to the signup page. And from the signup page, I want to save the user data to the database (I am using firebase) and show the result of data on the next page.
To calculate BMR:
Page 1: Goal
Page 2: Sex
Page 3: User enters height, weight and all
Page 4: Signup
I have implemented the formulas, and they are working well. But I want to save the user-selected data (which is been passed to the signup page) from the signup page into the database and show the result of calories on the next page.
Please any suggestion is appreciated.

I made an industrial form, check-in and check-out of the equipment, I use the firestore to store all the values, I happen to always leave it separate, a folder for men and another for women to facilitate the search later

Can you please elaborate and explain the steps? It would be helpful for me.

@Mevi Can you please help me out with this query?

first is to make a way to get the information and then the firebase steps are very detailed in the documentation (configuration, create a data resources with the items that will be sent and finally, send to firebase)

A tip, in the next comments, try to deepen your doubts.

I guess You use Firebase authentication as well then, right?

All You need is basically a Firestore collection of users. So create a Data resource in Appgyver data confiugration menu. Add all the required properties you store about the user in your forms already and add a few other fields: idToken (to be able to send registration verification emails, password reset etc.), email address, maybe a name, to make it personal etc…

Now on the signup page you need to signup the user with an HTTP request. You need to use identity toolkit api from Firebase.

Now right after the register user HTTP request You can and I guess should add a “Create record” flow for a user record to store all the data in Firestore.
For idToken, email You can use the outputs[“HTTP request”].response.idToken and .email respectively. Please check the correct syntax to avoid errors.
In the create new record flow function I would create the record as an “object with properties” (I mean this is the data binding selection). This way you can assign each property its value from all the different variables and outputs You have from the app.

Now when the user launches the app again and logs in, you need to create a get record collection flow, with one custom filter formula, email equals “Get current user” email. Set a new data resource or app variable “selectedUser” to the outputs of the get record collection. So You have one record for that collection, thus the value would be in formula binding type: outputs["Get record collection"].response[0], or something similar.

Now You gathered data from your user, let them sign up and also can retrieve their data on log in again.
Hope this helps.

Thanks for your response. Yes, I am using Firebase authentication.

  1. I have already created the data resource (in the Appgyver) of all the properties I would like to save. And have created these documents in the corresponding firebase database with a similar schema.

  2. I have used the google toolkit for the Signup page and successfully a user can sign up.

  3. When the user logs in again, you mentioned using a custom filter formula. Can you please explain that part? That should be on the login page?

Yes, exactly, as you show in the picture in the 3. Point. That should be done on the login page. After both login flows. I mean the “get current user” and “log in user” flows.

Thanks. I have one more issue.
Referring to point 2, after the create record flow function I have passed the parameter (formula for calorie calculation) from the previous pages. Because of the create record flow function, I am not getting the result of the formula.

(previous page 1)

(previous page 2)

(Signup page)
Can you please suggest how to resolve this issue?

Sorry that it took me soo long to reply.

I am not totally convinced that the issue is with the create records flow functions.

But one sidenote that can help Your development. If You set an appVars You don’t even need to use the params. As appVars are available on all pages.

So I would only pass on the appVars, if you really want to pass that on as a pageParams. After that complete the calculation formula on the new page for example on “page focused” event.

I have used appVars only at maximum places, but when I have to pass the data from the previous page to the next I have to use param. For eg:

I have passed the formula for the BMR using the page parameter

The user is directed to the next page

On the above page, I passed the parameter BMR value and continued the calculation based on user selection.

So there is a calculation going on by forwarding the result of the previous page. So I have to use page parameters for that. I hope you understood my issue.

I perfectly understand that You have an ongoing calculation. However I still suggest doing it in the way that:

IF() condition → true → set page variable BMR (use the formula here) → open page with params and pass on the finished calculation into that.

I am not a 100% sure that this is the issue, but it is worth a try.

Thank you so much. I was able to get the result of the calculation on the next page. In the above comments, you mentioned using a “page focused” event. Can you explain that part?
“After that complete the calculation formula on the new page for example on “page focused” event.” this thing.

1 Like

Glad You got it to work.
That referred to the page’s logic canvas.
So in the layout tree click on the “page layout”.
Open the logic canvas. There you should see the default two events “page mounted” and “page focused”. If they are not there, You can drag onto the canvas the “Receive even” flow and in its properties select the page focused event.

Page focused even will trigger each time the page becomes the focus… So for example after closing a modal window or after navigating to the page.

Thanks. Some more queries, how to retrieve the data (BMR), when the user logs in?
get record → set app variable → open home page
I am using this flow but it’s not working

Hello, I am able to save the data to the database, but all the numbers are written as strings in the database.
And for one of the create record functions, I am getting an error as “INVALID_ARGUMENT: Cannot convert firestore.v1.Value with type unset.”
I am not sure what is wrong?

Try doing a conversion with formula NUMBER for those fields :slight_smile:

1 Like