How to get Current user details from Firebase database

Hello Everyone.

I have build an app with firebase user authentication with email and password working fine. Each user sign-up in my app create a user record like username, email, mobile… on firebase database on a collection named userDetails with document ID as the unique user UID and all works well.

I want to retrieve the current signed-in user data like Name and Email to user profile page when any user signed in.

Set up a firestore database with all the document properties and add a data variable on the profile page from that data resources and collection. Whenever I try to output the Name of the current user it gives the output Name, but from the document that’s at the top of the collection list. I didn’t get the mentioned in the above forum, could any one explain that.

I tried to bind the email field value with filter the current user document using PICK_ITEM(data.userDetails,0).userEmail the Index ‘0’ gives the email from the first document.

How can I change the index to ‘currentUser’ index number from any other static value? or Is there any other method to retrieve specifically the current signed-in user details from the database collection with many users documents.

Also tried SELECT(data.userDetails, item.userlocalId == appVars.userUid) to get the current user document but it says “Should use a number to access the list item instead of list type”. Same error while using MAP() function instead of SELECT().

Search and read many Appgyver forum everywhere mentioned “currentUser.id , currentUser.email …” but whenever I tried to add currentUser it won’t comes in my app. Little confused. Solutions and helps are appreciated.

Thanks
Bravo.

1 Like

Instead of select use FIND(). Or better FIND_BY_KEY().

That finds only one object. The SELECT() returns an array (or list).

Tried like bellow, but won’t work… I think there have some issue, could you please correct it?

PICK_ITEM(data.userDetails, FIND_BY_KEY(data.userDetails, appVars.userUid, data.userDetailsName.userlocalId)).firstName 

Also tried

PICK_ITEM(data.userDetails, FIND(data.userDetails, item.userlocalId == appVars.userUid)).firstName

Calling @Mihaly_Toth @F_ORTELL @Cecilia @Fred_Kuzyk for help!

1 Like

As far as I can feel from the formulas You do not get a collection of records but only one record. How do You fetch the “data.userDetails” from Firebase?

That should be a “Get record collection” with a filter formula where You put the localId equals to user email…

Have you tried GetRecord flow function?
It show be as easy as that

Tried but it couldn’t fetch any details.

Get record flow mounted to profile page, that every time user open the profile page, it retrieve his name and other details from the database. But doesn’t work here.

use this formula to get the document id for the current user.

Add a toast to your GetRecord on both outputs, see what message or code you’re getting

The negative(second output) gives nothing… and the first node gives nothing(toast appears with nothing shown in it) when I use " outputs[“Get record”].record.firstName " also I tried with static text “Hai” on first node it return that in toast.

Can You also show how is the data.userCredential assigned?

The issue here is 90% the lack of any data… So let me talk You through the process.

You mentioned in Your first question that the document id is the UID of the user.

So what You need to do is a Get record flow where the document id is the uid. You can get the uid from the log in logic flows. So on the authentication page You can do the flows like this:
Email user auth ( first output has a property UID) —> get record flow (id equals to the UID) and then set Your app variable to the output of this flow.

In case the issue is that document id doesn’t equal to the UID (which is most probably happening if You use Firebase connector…) instead of the Get record flow use the Get Record collection and do a “filter” where You set the filtering condition to UID equals to the output of the authentication flows. Then set the user app variable to formula where You do this:
outputs[“Get record collection”].records[0]

Hope this clarifies a few things.

I use REST API HTTP flow function using PATCH method(“https://firestore.googleapis.com/v1/projects/{PROJECT ID}/databases/(default)/documents/{COLLECTION NAME}/” + appVars.userUid) to create info after Sign-up HTTP flow function on sign up page. Works fine It create User details with document Id as UID(checked its correct), fine.

Yeah, I tried to use that method by adding filter to Get Collection flow function like

id → equals → appVar.UID

It also doesn’t work for me.

I didn’t get this part…

Very much confused, and I can simply say don’t know what this [0] stands for. First document or current user???

OK,go to firebase and copy a UId. on the GetRecord, paste the UId and try again. If Ths does not work you’ll have to use rest API integration method to get data from firebase

Great, gives me the exact result from the document with UID… then where is the problem. May be with the formula that I bind to get the document ID of the current user from the collection list??

I think your UId variable is empty… If you’re getting something when paste the UId in the get record and nothing when you’re using your variable, it means your variable is empty.
Assign the app variable UId immediately after the user logs in

You are right @F_ORTELL the appVars was empty… But I managed to get the result by assigning value to my appVars.userUID. But the issue is when I tried to open the profile page from the Home page, the value of the variable shows ‘undefined’ first time after few seconds it shows the exact value from database.

I add my getrecord flow function to page mount event. I tried page focused also nothing comes in page focused event. Pic bellow…

Any suggestions

Assign it directly to your component…
Like, GetRecord>Component. You can use flow function to change component values from elsewhere, i forgot the name of the flow function. I think is SetComponent something something. Try looking for it n the flow function market. Is really useful

I literally had to use TeamViewer to access my laptop for Ths… :joy:

You need the SetComponentProperties…

You then select the component you want to do it to then set the value…

So is going to be :PageMount>GetRecord >SetComponentProperties

In SetComponentProperties… Component is the name of the component you want to target, property name is what you want to change or set… Content is the value you want set

You’re awesome @F_ORTELL

That’s great!! Your suggestion work like fire, my friend. Many thanks!!
I’ll poke you again, whenever I stuck somewhere :grinning: :grinning:

You could just move the hide spinner flow after the “set data variable” flow, so Your page doesn’t show until the data is available. :sweat_smile:

I have a problem on the same @F_ORTELL @Mihaly_Toth that, it wont show up the value until the page is refreshed by saving after any changes on composer pro. While retrieving it pick the exact document value of the signed in user, that’s fine.

Tried, using delay, page focused, page mounted, or even with variable changes event by adding a separate variable, all fails.

Scenario —>

Soon after sign in with a user credential to my app, use navigation menu icon to go to my profile page where I want to show up the current user details that already stored in my database saved while sign up.

After sign in, when I tap the profile navigation icon, open the profile page but all the user information details are blank, wait for long to check if takes some time but not retriving any data from database. Then I check going to another page and come back to check again still the same, no values.

The fun part comes here… Then I go to composer pro and drag any flow function(literally I want to save the application again) little bit and save the app then go and check the preview app again, all data are shown up in exact place. From this moment it keep showing the data all the time I come back to my profile page.

Then sign-out from the user and sign-in again to check, the data disappear again. And show up again once I go to composer and do something then save the app.

Did you get my point? and can you figure out what’s happening? Any solution for this?

I guess, if page refresh automatically when I enter the page will solve my issue… Search for many forum article to refresh the page, I couldn’t found any solution that solve my Issue…

When you click on the profile navigation button, your supposed to see details, to do Ths…
You use pagemount>GetRecord>SetComponentProperties… It should load automatically for you