I`m trying to set a Firebase rule that will grant access to R/W, if the $uid is equal to auth.uid. I signed in with firebase phone auth.
Here is auth section of my project:
And this is my database structure:
I'am trying this rule:
{
"rules": {
".read": "auth != null",
".write": "auth != null"
}
}
and this rule :
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}
I get an error (Permission Denied), when I try to access the data.
AppController.getInstance().userid = String.valueOf(mAuth.getCurrentUser().getUid());
Log.d("PhoneAuthuid2",AppController.getInstance().userid);
Firebase ref = new Firebase("https://xxxdatabase.firebaseio.com/users/");
ref.child(AppController.getInstance().userid).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
final User userbilgi = snapshot.getValue(User.class);
Intent intent = new Intent(activation.this, anamenu.class);
intent.putExtra("useruid", userbilgi.getUseruid());
intent.putExtra("phonenumber",userbilgi.getPhonenumber());
intent.putExtra("userdurum", userbilgi.getUserdurum());
intent.putExtra("now", userbilgi.getNow());
intent.putExtra("lastclicktime", userbilgi.getLastclicktime());
intent.putExtra("clickcount", userbilgi.getClickcount());
intent.putExtra("totalclickcount", userbilgi.getTotalclickcount());
intent.putExtra("coincount", userbilgi.getCoincount());
intent.putExtra("satlink",getIntent().getStringExtra("satlink"));
intent.putExtra("reklink",getIntent().getStringExtra("reklink"));
startActivityForResult(intent, 1);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d("PhoneAuthFirebase",String.valueOf(firebaseError));
}
});
I`m following the Firebase instructions and this rules pass the simulator.
I`m not getting the instance with snapshot from Firebase when these rules are in place.
I would be very grateful if you help to solve the problem.
UPDATE :
Here is simulator result :
I am trying simulator grant access to read or write. But not in real device. I cant get data from firebase.