# Cloud variables and user ID

**URL:** <https://community.thunkable.com/t/cloud-variables-and-user-id/1434493>\
**Category:** Questions about Thunkable X\
**Tags:** firebase, beginner\
**Created:** [August 6, 2021, 12:11pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493 "2021-08-06T12:11:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 12:11pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/1 "2021-08-06T12:11:56Z")

</div>

Hi  
I am trying to save my items to Firebase through Cloud variable but also for a specific user.  
I have created a sign in page with a sign in component and I have put the logged in user to a variable just to make it easy to use later in the app.

Now I would like to add my items inside of that user somehow. I know how to do this in the Real time database component but I am trying out the cloud variables now and I feel I would need some help.

Anyone with any tips for me? Thanks!

This is my database today:  
 ![Screenshot 2021-08-06 at 14.03.02](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/3/93793b6c4a7fb8429a1fd82990098daaccf9a2fb.png)

I would like it to end up more like this:  
 ![Screenshot 2021-08-06 at 14.02.43](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/6/66492c7361fb9c60d32c87501166d9a7221c4fde.png)

This is my “save” block where I tell how the info should be saved in database:

 ![Screenshot 2021-08-06 at 14.02.25](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/7/37a8533240f19875f3577a97aafd2d786beb0696.png)

So, now things works but nothing that I save are connected to any specific user.

Thanks guys!  
/Andreas

---

<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:** [August 6, 2021, 12:50pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/2 "2021-08-06T12:50:42Z")

</div>

I’m not sure of what you are trying to say but if you want to store the list under the user ID then you need to create a cloud variable to point to that `node`

See an example of my project  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/1/c1126ed75e04d199cb960498ebaca416c026bf20.png)

Each student using my app has a unique user ID and all the student info is saved under this user ID.

This will save the list under a bucket called “myProject” under the user ID specified.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/0/10d64b7c88dd76635c42f7055e9bcd31eb3c4bf6.png)

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 1:14pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/3 "2021-08-06T13:14:04Z")

</div>

Ok great, thanks. Yeas that’s kind of what I am looking for. May I ask, is “set cloud variable…” (the block you have used) kind of the same thing as using the block “initialize cloud variable block” (which is what I have done) ?

What would be the difference really? I have been looking at this block already but couldn’t really understand it and why…  
When do I use the “initialise block”, and when do I use the “set-block”?

Thanks  
/

---

<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:** [August 6, 2021, 1:21pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/4 "2021-08-06T13:21:08Z")

</div>

The variable that are created by the `Initialize block` are fixed variables and the name of the variable cannot be changed. When accessing Firebase RTDB using the `cloud variables` you will often need to change the node structure dynamically and for this you use the other type of variables.

See this example

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/8/f88c226fb1b6dca47357f880f0de4ecf5f2b0e84.png)

Which cannot be done at initialize time.

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 1:37pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/5 "2021-08-06T13:37:06Z")

</div>

Ok I see. Thanks!  
but if I set a variable like this, why wouldn’t my items be under my user ID then? Am I misunderstand something?

 ![Screenshot 2021-08-06 at 15.34.44](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/1/11e55c84e41284933820fd285cd1abfc53ac3e0d.png)

Its directly under my “name” of the list. No userID is being shown in the database.  
 ![Screenshot 2021-08-06 at 15.38.08](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/b/6b45ed0154b8f4cce5a68171a2ed2cd73fee4bb8.png)

I noticed that you added something what I think looks like a userID in the name of your variable?  
 ![Screenshot 2021-08-06 at 15.39.55](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/b/8b5881350751088bfbec9d6fa63eda1ff9fb06c5.png)

---

<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:** [August 6, 2021, 1:40pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/6 "2021-08-06T13:40:38Z")

</div>

> [@andreas.sjdtomypv](#):
>
> if I set a variable like this, why wouldn’t my items be under my user ID

This will actually replace the value in the iser\_ID key. You need to add another “/” and a key to save the values under it.

> [@andreas.sjdtomypv](#):
>
> Its directly under my “name” of the list. No userID is being shown in the database

It he `app variable user_ID` is **null** then the values will be saved under the upper key.

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 1:50pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/7 "2021-08-06T13:50:35Z")

</div>

Thanks!!  
I got it to work! I think the reason why it didn’t work first was I needed to logout and login again…

This is the block now which seem to be working ok:

 ![Screenshot 2021-08-06 at 15.49.00](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/4/445010368b7588cacd649bf4ed4c2a74993ee121.png)

---

<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:** [August 6, 2021, 1:55pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/8 "2021-08-06T13:55:03Z")

</div>

I can see you are still using a list inside a list. You should use the `app variable localList` directly without the `list component`  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/0/c0e8c3048dd4c14a56481434bb4bb1e977166b4d.png)

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 2:02pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/9 "2021-08-06T14:02:19Z")

</div>

o yea your right… I did remove that earlier but some how it came back it seems…

may I ask, when using the “set” cloud variables, they are not named anywhere…? How can I use them later in the app?

For example, I saw this in the thunk.docs:

 ![Screenshot 2021-08-06 at 15.59.23](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/8/f85aca3ed175dedfa1363ac2c95b59599c5aa9b6.png)  
and here it looks like they have “named” these cloud variables. When I try I only get this dropdown with types, I can only see how I can name these if I do a fixed (initialised) variable…?

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 2:09pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/10 "2021-08-06T14:09:33Z")

</div>

what I would like to do is to do do as in this guide,

when SAVE the list, use the “cloud” variable and make text from the “local” variable,  
And  
when GET the list, use the “local” variable and make list from the “cloud” variable.

I get this to work when using fixed (initialised) variables, but as I am not able to name the “set”-variables I don’t get how to pick up the cloud-variable in the GET method…??

---

<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:** [August 6, 2021, 2:16pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/11 "2021-08-06T14:16:52Z")

</div>

The **unnamed variables** are actually keys in Firebase so you will always refer to the key as the name of the variable.  
For example, if I want to check the last time the student logged in I will use the **unnamed variables** to access the data this way  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/9/f90ad12e33c4ee9b5154151e966362c25dee8ad5.png)

I’m not using variables but actually constructing the **Firebase node** to retrieve data.

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 2:31pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/12 "2021-08-06T14:31:44Z")

</div>

Great, thanks for the explanation.  
Then I ended up with these blocks, and it looks like it’s working. Thanks a lot!

SAVE

 ![Screenshot 2021-08-06 at 16.29.58](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/0/8/080dabf1f3c96dd4c0c5080611bb0e25c87908d7.png)

GET

 ![Screenshot 2021-08-06 at 16.30.02](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/2/6/260db32306db3cbafd46de43b13da571e436dc8c.png)

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 8:35pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/13 "2021-08-06T20:35:11Z")

</div>

May I ask, I believe I got everything to work as I want now. But I notice that when start the app, and the items are syncing with the database, the process are really slow, its probably cause of how I have wrote it. But would you have any tips to me how I could set it up to be more fast in its sync-process?

I have chosen to, when start the app, delete all rows from my DVL and then get the data from the database and create new rows for every item of that data into my DVL-list. And yea, I’ve put all this in a function and call on in my “open screen-block”. This seam to be a bit lagging and probably I could do this some other way?

This is my block for the function that runs when opening the app:

 ![Screenshot 2021-08-06 at 22.31.13](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/9/795aaa2ea3c4f50e6fb9bf652f54d2663be84e22.png)

And here you can see a small video showing what I’m talking about. Its clearly lagging when startup the app. But nothing is missing and everything works how I like…

[https://dl.dropboxusercontent.com/s/lmrdvszebkuyxt8/RPReplay\_Final1628279696.MP4?dl=0](https://dl.dropboxusercontent.com/s/lmrdvszebkuyxt8/RPReplay_Final1628279696.MP4?dl=0)

Thanks!

---

<div class="post-metadata">

**Author:** ![jonathonschnoor6x4b5](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jonathonschnoor6x4b5/32/112262_2.png) [@jonathonschnoor6x4b5](https://community.thunkable.com/u/jonathonschnoor6x4b5)\
**Post date:** [August 6, 2021, 8:59pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/14 "2021-08-06T20:59:16Z")

</div>

You could just hide the list viewer, have a loading icon, and when it’s added all the items, show the list viewer and hide the loading icon.

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 9:39pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/15 "2021-08-06T21:39:58Z")

</div>

Thanks! Great idea!! So simple but so much cleaner! 👍

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 10:04pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/16 "2021-08-06T22:04:21Z")

</div>

This could actually be a really great idea, I have set up something like that now, but I notice that there is still a DVL showing -before- the screens “open or start”-block runs. It is something like “the last view list” or so, not synced… That is shown for like a half. second or so…  
How can I hide that also? Any ideas?

I did something so simple as this now, and it works fine, except for that “dead” list in the very beginning…

 ![Screenshot 2021-08-07 at 00.05.24](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/5/e52b0b7563a8bc6ebbb9addd33d6c051f73a59a6.png)

---

<div class="post-metadata">

**Author:** ![jonathonschnoor6x4b5](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jonathonschnoor6x4b5/32/112262_2.png) [@jonathonschnoor6x4b5](https://community.thunkable.com/u/jonathonschnoor6x4b5)\
**Post date:** [August 6, 2021, 10:06pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/17 "2021-08-06T22:06:39Z")

</div>

Sure, it could be that it’s visible in the project editor. To fix this, you could just select the list viewer (in the editor) to `Visible : False`

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 10:08pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/18 "2021-08-06T22:08:44Z")

</div>

yea, that was it, so simple. Thanks! 🙏

---

<div class="post-metadata">

**Author:** ![jonathonschnoor6x4b5](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jonathonschnoor6x4b5/32/112262_2.png) [@jonathonschnoor6x4b5](https://community.thunkable.com/u/jonathonschnoor6x4b5)\
**Post date:** [August 6, 2021, 10:09pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/19 "2021-08-06T22:09:37Z")

</div>

Not a problem, and happy to help!

---

<div class="post-metadata">

**Author:** ![andreas.sjdtomypv](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@andreas.sjdtomypv](https://community.thunkable.com/u/andreas.sjdtomypv)\
**Post date:** [August 6, 2021, 10:42pm UTC](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493/20 "2021-08-06T22:42:20Z")

</div>

Sorry guys, I am not sure if I do wrong in adding this question here, but I am really happy with the app now, and I am trying to provoke it just to make sure nothing weird is happening. Then when I tried to login with a new user I started with an empty list as suspected. But then as soon as I entered a new item the items from the previous user showed, an the new item I added was added to that other users list.

But then I tried to login with a third user, and that went fine all the way. Nothing weird happened, it started with an empty list and as I added new things it was only these that was shown.

Then I logged back to the other user which acted weird and removed all the items from it and started over and now that user acts as suspected as well.

I am wondering, is there anything I could add to the code to prevent these kind of things to happen?

I guess it should be the “save” block which may missing something, as the old users list appeared only after added a new item?

This is my save block:

 ![Screenshot 2021-08-07 at 00.37.54](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/c/bc4d542a2383b00398658e28b994fdf935ce9c04.png)

This is what happened in my databas when added a new item to my new user:

 ![Screenshot 2021-08-07 at 00.29.34](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/6/2/620bdece31d15322b37aeaf0e002e24f7436a837.png)  
As you can see the first five items was another users items, not this users.

or maybe this is a cache-issue and wouldn’t likely happen in real life as people have different devices?

Thanks a lot!

[Next page](https://community.thunkable.com/t/cloud-variables-and-user-id/1434493.md?page=2)
