0

Below is the rule.

  {
      "rules": {
        ".read": true,
        ".write": "auth != null"
      }
    }

Here is the code I am using to add. The line mAuth,getCurrentUser.isAnonymous returned false and userid also printed the value. The user is authenticated but unable to write to users table.

System.out.println("Anonymous - "+ mAuth.getCurrentUser().isAnonymous());
mRef = new Firebase("https://moe-90cc7.firebaseio.com/users");
String userid = mAuth.getCurrentUser().getUid();
System.out.println("userid---" + userid);
mRef.child(userid).setValue("1");

When I change rule to

read: true
write: true

it works fine, but the point is why its not working with auth!=null rule when I am authenticated user.

Is there anything I can do to double check if the user is authenticated or not?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user7327850
  • 229
  • 5
  • 15
  • You're mixing Firebase versions 2.x (e.g. `new Firebase(...`) and 9.x/10.x (e.g. `mAuth.getCurrentUser()`). So while you have an authenticated user in Firebase 9.x/10.x, your connection to the database is unauthenticated. The solution is to make sure you use Firebase 9.x/10.x exclusively and remove the dependency on Firebase 2.x from you gradle files. – Frank van Puffelen Dec 28 '16 at 15:31

1 Answers1

0

This means that you have to authenticate user which is updating realtime database. you can authenticate user via some login methods as provided by google.

you can check this link for gmail authentication

ʌɐɥqıɐʌ
  • 137
  • 16
  • I am already using Google authentication. I think that this line mAuth.getCurrentUser().getUid(); itself proves that I am authenticated.. – user7327850 Dec 28 '16 at 07:32
  • It returns the valid key and the account also got added on firebase authentication UI – user7327850 Dec 28 '16 at 07:33
  • i think you have to include the authenticated account in you realtime database project then only you can be authenticated i guess. – ʌɐɥqıɐʌ Dec 28 '16 at 07:34
  • go to authentication tab in firebase and you will get sign-in methods and users. i hope you understand. – ʌɐɥqıɐʌ Dec 28 '16 at 07:37
  • They are already added on the firebase UI.. I am able to add records to location table but not able to add to user table .. – user7327850 Dec 28 '16 at 07:37
  • if you are able to add in one table and not in other then there is something wrong with your key which you are passing or check your table name. but you can check if account which you are using to login must be added in user. – ʌɐɥqıɐʌ Dec 28 '16 at 07:40
  • How to check that ? – user7327850 Dec 28 '16 at 07:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131662/discussion-between-vahqiav-and-user7327850). – ʌɐɥqıɐʌ Dec 28 '16 at 07:43