In the management screen I have both email auth and anonymous login enabled. The data has only one node - Hello: "World"
The rule that I have is
{
"rules": {
".read": "auth != null",
//".read": true,
".write": true
}
}
If the user is NOT logged in with the above rule then you get The read failed: Permission denied That's all good.
If a anonymous user is logged in then I can see the value "{Hello=World"} Works so far.
If i log in with a email user the I get an error :FirebaseError: Permission denied
The onAuthenticate does trigger and I get : User ID: 3c6ce912-a05a-49ed-ae68-8ec97d022303, Provider: password
The complete code is below. What am I doing wrong?
import com.firebase.client.AuthData;
import com.firebase.client.DataSnapshot;
import com.firebase.client.Firebase;
import com.firebase.client.FirebaseError;
import com.firebase.client.ValueEventListener;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class FirebaseTest {
Firebase ref = new Firebase("https://<FIREBASE NAME>.firebaseio.com/");
public FirebaseTest() {
//logonAnonymous(); //works
logonEmail(); //permission denied
showValues();
try {
System.out.println("Waiting for input");
System.in.read();
} catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void logonAnonymous() {
ref.authAnonymously(new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
// we've authenticated this session with your Firebase app
System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
System.out.println("Anon user auth error " + firebaseError.toString());
}
});
}
private void logonEmail() {
ref.authWithPassword("myuser@home.com", "secret", new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
// there was an error
}
});
}
public void showValues() {
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println( " value -" + snapshot.getValue());
}
@Override
public void onCancelled(FirebaseError firebaseError) {
System.out.println("The read failed: " + firebaseError.getMessage());
}
});
}
}