Save Item under Firebase





The first screenshot is how I store the value (for example, storing the name a user inputs.) The second screenshot is how I retrieve that value from another screen. The third screenshot is the rules in the Realtime Database. I’ve used many different sets of rules from your website as well as the one you’ve provided earlier, this is the one I have in it now. And the fourth screenshot is how my database is structured in Firebase.

OK, you are mixing up the RESTful api with the firebase component (this will not work), and I am not quite sure how you are able to post any data to firebase at all ?

Where you indicate "App Name", I am presuming this is listed as your Project Bucket in your Firebase designer settings ?

I will need to provide you with an example, which will take me a little while to put together.

First part is to sign in as an authenticated user.

I created two users in the console (but this can be done in the app using the "signup" url). You then need the apiKey for your project, and the user email and password to sign in. When the sign in data is returned, we set the json response as a dictionary, and extract the UID and the idToken for further use (I put the UID and idToken in a label for demonstration purposes:

image

Second part is to set the rules

Because you appear to want your app name as a project Bucket, I have included this as such. The rules will only allow authenticated users to read and write data to their own UID node in the projectBucket "aaaFBusers". There is double security here with your app, which will only return the currently signed user's UID.

{
  "rules": {
    "aaaFBusers": {
      "$uid": {
        ".read":  "$uid === auth.uid",
        ".write": "$uid === auth.uid"
       }
     }
  }
}

Third part is to save some data for a signed in user

I have followed your data, so I will save an email address and full name, under the user's UID, in the project Bucket "aaaFBusers". I have used a second web component for clarity. You will see from the setting of the blocks how in firebase, the data is saved under the current user's UID. In the screen, I have captured the return from firebase of the data set. Note that you must follow strict json format in the PutText.

Screenshot 2022-08-28 11.33.14

Screenshot 2022-08-28 11.33.38

I have then signed in as the second user, and posted some data under their UID

image

Fourth part is to get the data back

To demonstrate, I will first attempt to return all the data in the project Bucket "aaaFBusers" as an authenticated user.

image

image

As you can see, this returns an error: Permission denied, because the authenticated user does not have permission to read the entire project Bucket data.

Now we will include the user's UID in the blocks

image

image

and you can see that all the data under the user's UID is returned.

If I try to use the other user's UID I get Permission denied again

image

Hopefully that covers everything you need to know :slight_smile:

2 Likes

Can you send an AIA? I’ve done most of the stuff but I want to make sure everything’s right

aaaFBusers.aia (4.4 KB)

1 Like