# Realtime DB User ID

**URL:** https://community.thunkable.com/t/realtime-db-user-id/1041878
**Category:** Questions about Thunkable X
**Created:** [December 28, 2020, 8:56pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878 "2020-12-28T20:56:08Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 28, 2020, 8:56pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/1 "2020-12-28T20:56:08Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/b/1bbd3c274877723d426c9bd1ead728221020ee9b.jpeg)  
‘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?

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [December 29, 2020, 8:08am UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/2 "2020-12-29T08:08:55Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 29, 2020, 10:02am UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/3 "2020-12-29T10:02:52Z")

</div>

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)

 ![Screenshot 2020-12-29 124008](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/3/73f867c80ada5419ee205de6fb294b80cd3efd0f.jpeg)

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).

 ![Screenshot 2020-12-29 124227](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/9/e9e7e5fec54573735c9fa31d6193d7d57ac8eb93.jpeg)

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

---

<div class="post-metadata">

### Author: ![drted](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/drted/32/92694_2.png) [@drted](https://community.thunkable.com/u/drted)
#### Post date: [December 29, 2020, 2:02pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/4 "2020-12-29T14:02:59Z")

</div>

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

> [@\[Solved\] Working with cloud lists](http://community.thunkable.com/t/working-with-cloud-lists/1040317/2):
>
> @jared, Glad to see you have come into the light (Firebase) and rejected the darkness (data sources). crazy_face The way Thunkable and Firebase interact on lists is the problem. Firebase assigns number to each item in the list. From my limited [reading](http://book.mixu.net/node/ch5.html), lists (aka Arrays) are sequence dependent. This seems like the rationale for Firebase assigning numbers. [image] (apparently) Thunkable assumes that the array/list in Firebase will be a zero based listed with no gaps. If there are gaps, Thu…

---

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 29, 2020, 2:17pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/5 "2020-12-29T14:17:51Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [December 29, 2020, 2:18pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/6 "2020-12-29T14:18:27Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/e/ce35bb0743daa4b65c546e014fe76f0d1aeed264.jpeg) ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/5/b573434d9280b31ad0948877e7bc5eb15d8b02f3.jpeg)

---

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 29, 2020, 2:19pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/7 "2020-12-29T14:19:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 30, 2020, 12:30pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/8 "2020-12-30T12:30:11Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/c/2c6b9ba70bc9291a93f3c10fdc5978f3fbd434cb.jpeg) ![Screenshot 2020-12-30 122830](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/6/f6f8f8b8a5c5f8d9dfa2d558eb261e0f9b5a5e4c.jpeg)

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?

---

<div class="post-metadata">

### Author: ![jared](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jared/32/138473_2.png) [@jared](https://community.thunkable.com/u/jared)
#### Post date: [December 30, 2020, 12:50pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/9 "2020-12-30T12:50:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![huntermclarkn](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/huntermclarkn/32/66310_2.png) [@huntermclarkn](https://community.thunkable.com/u/huntermclarkn)
#### Post date: [December 30, 2020, 1:07pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/10 "2020-12-30T13:07:47Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 12:19pm UTC](https://community.thunkable.com/t/realtime-db-user-id/1041878/11 "2024-11-08T12:19:21Z")

</div>


