Firebase - How to write/read data per user after authentication

后端 未结 2 1438
心在旅途
心在旅途 2021-02-04 10:29

I have tried to understand but not able to see how and where might be the data I am storing after login is going.

public static final String BASE_URL = \"https:/         


        
2条回答
  •  一整个雨季
    2021-02-04 10:39

    First, modify the Firebase rules as follows:

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

    Then, in Java Code:

    Firebase rootRef = new Firebase("https://user-account.firebaseio.com/");
    // Assuming the user is already logged in.
    Firebase userRef = rootRef.child("users/" + rootRef.getAuth().getUid());
    userRef.child("message1").setValue("Hello World");
    

    In the end, the data would look something like this:

提交回复
热议问题