-1

I'm new to Firebase platform and trying to add a hashmap with info about a user to the database:

    private void storeInfo(FirebaseAuth auth) {
        HashMap<Object, String> userInfo = new HashMap<>();
        userInfo.put("email", email);
        userInfo.put("name", fullName);
        DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users");
        reference.child(auth.getUid()).setValue(userInfo).addOnSuccessListener(aVoid -> {
            System.out.println("data added");
        }).addOnFailureListener(e -> {
            System.out.println("failure");
        });
    }

and neither OnSuccessListener nor OnFailureListener gets triggered.

Realtime Database rules:

{
  "rules": {
    ".read": "auth.uid !== null",
    ".write": "auth.uid !== null"
  }
}
Arthur
  • 27
  • 8
  • Are you sure you're authenticated? Is any of the callbacks triggered? – Alex Mamo May 03 '22 at 12:55
  • @AlexMamo yes, if I print out auth.getUid() it prints it out. What do you mean by callbacks? – Arthur May 03 '22 at 12:57
  • Does `System.out.println("data added");` or `System.out.println("failure");` print something? – Alex Mamo May 03 '22 at 13:13
  • @AlexMamo nothing, they don't even get triggered – Arthur May 03 '22 at 13:16
  • 1
    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 May 03 '22 at 13:33
  • @FrankvanPuffelen thanks, but I changed the security rules for the realtime database to the ones shown in your answer in the link you provided and it didn't fix the error. It doesn't add the hashmap to the database and the callbacks don't get triggered – Arthur May 03 '22 at 18:02
  • Can you edit your question to show what you've done? We probably don't need to see the Storage security rules, so you might as well get rid of those at the same time. – Frank van Puffelen May 03 '22 at 18:08

1 Answers1

0

Finally solved. The solution to the issue I had is described here:

https://stackoverflow.com/a/69531227/10761567

Basically the problem was that google-services.json file didn't contain the url to the realtime database (because the file was created before the database).

Arthur
  • 27
  • 8