Realtime DB User ID

I have my Firebase account linked to my app for Realtime DB and Sign In. Using Cloud Variables for the data collection. It works, and I am able to get users to create an account w/ unique User IDs. My problem is instead of the data being associated with the user ID which entered it, it is associated with a count-up. See Below
Screenshot 2020-12-28 205355
‘0’ and ‘1’ both have the right data and are associated with unique email address, and any additional data saved just continues the count up.

Is this something to address with code in thunkable (needing to use the official Realtime DB blocks), linking authentication with the Realtime DB or something else altogether?

1 Like

It seems you are adding info under the user ID but you are not providing a key for the info being added therefore Firebase generate the count or numbering which is the expected behaviour of the Firebase database. You can then retrieve the saved info into a list where every element in the list will correspond to a numbered entry under the user ID.

My question is more on how to be able to have data entered in the thunkable app following log in, be associated with that users ID on firebase. That will allow me to set certain firebase rules regarding use of the data. But if the data is simple a sequential count, I cannot set those rules.

UPDATE***

My original code saved the Cloud Var as a List (see below)

But, If I change the code to save the Cloud Var without a list, then the data is saved in Firebase beginning with the object fields (no numbering).

So my question is, is there a way to specify on a Thunkable App that an authenticated user of X user ID is the one altering the Realtime DB so as to make their User ID the Realtime DB key

I think this post will answer your question and show you how to create firebase herarchies incorporating the userid.

It is helpful, thank you.

When you mention UserID via the sign in block, is that the Thunkable block? or by saving “UserID” will it know to link it with firebase authentication userid?

You need to grab the user ID from the Firebase login blocks. It’s a really nice feature!!

See this example

I first use the value directly then assign it to a variable.

1 Like

That makes sense, I will give it new shots and let you guys know

It is working well! Thank you guys.

I do have another question though, I am able to successfully transfer text data to realtime DB and transfer “blank spaces” as just a text block. What is weird though, is if my text input is empty i.e the user did not put any text in it, then the database will not accept any transfer. I am failing to understand why the database does this if it can accept empty text boxes?

Screenshot 2020-12-30 122811 Screenshot 2020-12-30 122830

If all “Inputs” are filled with text then transfer goes ahead. Even if 2 blocks are taken out (like the second picture" transfer goes ahead. BUT, if say the Name input was empty, then no transfer would go at all. Not sure why the database does that?

1 Like

you cant assign a value null. it will nullify the entire save operation.

a workaround would be using the return block

if text input = null
return " "
else return text input

1 Like

Thanks

I had actually initialed tried that but used

if text input is empty instead of null and it caused the app to crash so I thought it was the whole function not my mistake of using empty instead of null. Thanks so much Jared

2 Likes