How can i get 2 tag values from firebase and compare it?

Hi, I'm currently want to make a simple login for user, the login interface will get 2 input from user which is username and password.. The user data already in the firebase with tag.. how can i get both username and password tag values from firebase and compare if it match with user input from the login interface?

Here is my data from firebase:

firebasecompare

and this is my code in mit app inventor:

codettnye

I suggest you reorganise your firebase structure, so that you save your data like this:

image

then call back the data for each user like this:

image

3 Likes

Thank you, really appreciate that, i will try..

sir where did you use the firebasedb1.projectBucket ?

You either set it in the designer, or set it with the block. In the example above UserData is a top level node (one below the project name) which is set in the designer.

1 Like

thank you for your help i think we have the same problem and I will try this blocks later

OK this intrigues me some and I want to use this method because it reduces the number of blocks that I have by a bunch. Let me see if I understand this..

The GetValue event reads in the entire list of user data for user "tbLoginUserName", which is set as the tag. This is a list.

Then, in the GotValue event you use the same username as the tag, and then separate the data with an If-Then statement for each "sub tag" in the list..

I don't understand the need for the If-Then statement .. why not just Set Label4, and the rest, as is? Seems to me that the GotValue tag is going to be equal to the username everytime, isn't it?

The if block is really just a placeholder, in preparation for other tags that may be called back, this will help to use just one .gotValue event block for many tag returns. For example:

image

Depend on how many tags and output locations you have as to how many extra code blocks / procedures / lists one might use to get through this. One can always use another FB component for convenience.

This particular data structure and Bucket/tag combo looks like it would return a dictionary instead of a list. Confirm this by using the is a dictionary and is a list blocks to test value after data arrives from Firebase.

2 Likes

Good idea. The results were YES that it is a dictionary.

I hate to be a pain, but I am trying to use this same structure to call my data and it is not working for me. I have been hacking at it all morning and am not making much progress. Here is what I know..

I am getting data into my GotValue event. I am placing the VALUE into one of the Notify blocks and can see the data.

I know my data is good, I can see it in the Firebase console. Here is a quick look at it.

image

My bucket is Users and my tags are the user names. (Yes, I am storing the UserName under the tag on purpose, I do have a use for it.)

I used a "is a dictionary" block and got back a TRUE result so my data is in Dictionary form and not a List like I thought? Even so, that doesn't help me enough as I am missing a lot of that knowledge at the moment.

My entire GotValue event is configured like this at the moment:
image
image

There are four more if/thens in the GotValue, I just didn't post them due to size but if you want to see them I can. They are all the same format.

I am defining my Bucket before I make any of these calls. See the GetValue image.

The "Not Founds" are me looking for specific points of data .. followed by the entire dataset that VALUE pulls..

Beyond that I am speculating and have tried many different combinations of blocks with no success.. can I get a little direction on how to read my data?

You probably need to refresh something...somewhere, your blocks look OK. However you appear to have a nested dictionary inside "Shirley" which I am not getting back ("Bob")?

This works for me

image

In your example data with Bob and Tom, you have two different formats for the DOB .. is that intentional? One appears to be treated like a string and the other a number?

It is because one set of data is generated using the firebase component, the other is generated just using the web component. (Not intended to confuse, I did show this earlier... the output return to the app is much the same, but you get back the extra escape \s with the firebase component method ). If you use hyphens for dates you won't get this problem.

Your Notifier is not helpful, being far removed from the blocks supplying it with data.

For debugging a .GotValue event, use two extra global variables

  • global debug_tag
  • global debug_value

and in the .GotValue event

set global debug_tag to tag
set global debug_value to value
set Label1.Text to get value for key 'age' in dictionary (get global debug_value) ...

In the Companion, this gives you stable places to apply Do It

  • get global debug_value
  • get value for key 'age' in dictionary (get global debug_value) ...

The extra overhead in passing the data through global debugging variables is a small price to pay to get well protected footprints at the crime scene.

1 Like

Ahh.. I see. That explains what I see when I look at my data on the Firebase server. Thanks, you guys truly are a wealth of information.

I found this block in the Firebase set of blocks and it pretty much solved all of my problems.

image

I was testing and the server kept writing data in another tag.. similar but not where I wanted. I added this block in front of all my Firebase routines, a 'refresh' as you suggested, and it works every time now. I guess Firebase can be finicky sometimes.