[SOLVED] Read user-role from Firebase and set a condition to navigate to different screen for different user role

I read many articles in the community about selecting the object properties and read from realtime database by Firebase, these kind of topics. But still can’t solved my problem.

Is there any problem in my code. The only thing I can nearly get is to show the json file from DB. But what I really want is to just showing the role properties’s value (which is Teacher, Student, or Admin) from the INFO. Can someone help me to solve this. Thank you !


1 Like

Firebase will normally send you results already as objects not as JSON. You should use the green value directly in the get property block.

Ex.
Get property “INFO.role” of object [value]

I also experiment to use label to see whether I can select the right property, the only success I can get is this, unsuccess one are all “null”.


1 Like

Thank you.
Just tried still won’t work. Is it because my key cannot select my user-name?
Not sure most of the tutorial show use UID and are after Login, but I cant generate one on first Signup right?

1 Like

I didn’t understand you.

You mean in the app variable user-name you have “QUIK ANG” but you get null?

1 Like

You can access the value of the “role” key in your database by using this block:

You can replace “QUIK ANG” with the UPPER CASE and user-name variable blocks by using a Join block from the Text drawer.

The “cloud” variable block is found in the Variables drawer and looks like this:

image

2 Likes

[Solved] Although I still can’t read data in Firebase, when I set (ACCOUNT/user-name/INFO/role). But I found out user uid can work, just that it only work when the user’s email is verified. So I change the login/signup flow.

User 1st register > back to Login Page > verify email > 1st time Login > Register User Detail (cuz UID just generated here) > Navigate to Page according to role.


While the 2nd Login will skip the Register Detail process.

Thank you for all. I really appreciate everyone help to let me experiment and test different ways to make it work! :grinning_face_with_smiling_eyes:

1 Like

@savequik
I looked at what you posted earlier as JSON and typed it in a string and found it working with this type of app
https://x.thunkable.com/projectPage/60a11a5e583ab400124b9b16

1 Like