Cloud variables and user ID

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

I would like it to end up more like this:
Screenshot 2021-08-06 at 14.02.43

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

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

Thanks guys!
/Andreas

1 Like

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

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.

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
/

1 Like

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

Which cannot be done at initialize time.

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?

Its directly under my “name” of the list. No userID is being shown in the database.
Screenshot 2021-08-06 at 15.38.08

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

1 Like

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.

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

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:

1 Like

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

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:


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…?

1 Like

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…??

1 Like

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

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

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

SAVE

GET

1 Like

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:

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…

Thanks!

1 Like

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.

1 Like

Thanks! Great idea!! So simple but so much cleaner! :+1:

2 Likes

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…

1 Like

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

1 Like

yea, that was it, so simple. Thanks! :pray:

1 Like

Not a problem, and happy to help!

1 Like

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:

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


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!

1 Like