0

I have been trying to display the user data saved on the firebase database to display on my app via TextView. I am not sure where my error is occurring or maybe my read/write permissions are wrong


    FirebaseAuth mAuth;
    FirebaseDatabase mFirebaseDatabase;
    TextView username;
    DatabaseReference myRef;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_settings);
        mAuth = FirebaseAuth.getInstance();
        mFirebaseDatabase = FirebaseDatabase.getInstance();
        myRef = mFirebaseDatabase.getReference().child("users");
        FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
        String userID = user.getUid();
        username = (TextView) findViewById(R.id.username);

        DatabaseReference ref = FirebaseDatabase.getInstance().getReference("uid");
        ref.child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String fName = dataSnapshot.child("fName").getValue().toString();
                username.setText(fName);
            }

            @Override
            public void onCancelled(@NonNull DatabaseError error) {
                Toast.makeText(getApplicationContext(),"Profile information failed.",Toast.LENGTH_LONG).show();
            }
        });

Here is my firebase rules

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth == null;
    }
  }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • What error do you get? – Frank van Puffelen Jul 25 '20 at 20:36
  • The security rules you're showing apply to Cloud Firestore, while the code you're showing is accessing the Realtime Database. While both databases are part of Firebase, they're completely separate, and the security rules for one don't apply to the other. To fix the error, you will have to set the rules for the Realtime Database. For a walkthrough of how to do that, see https://stackoverflow.com/a/52129163 – Frank van Puffelen Jul 25 '20 at 20:36

0 Answers0