I have tried to understand but not able to see how and where might be the data I am storing after login is going.
public static final String BASE_URL = "https://xyz.firebaseio.com";
Firebase ref = new Firebase(FirebaseUtils.BASE_URL);
ref.authWithPassword("xyz@foo.com", "some_password", new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
Toast.makeText(LoginActivity.this, "Login Successful", Toast.LENGTH_SHORT).show();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
}
}
At this point I am successfully authenticated and landed onto MainActivity
. Next in onCreate
of MainActivity
. I initialize Firebase
firebase = new Firebase(FirebaseUtils.BASE_URL).child("box");
// adapter below is an ArrayAdapter feeding ListView
firebase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue(Box.class) instanceof Box)
adapter.add(dataSnapshot.getValue(Box.class).getName());
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
adapter.remove(dataSnapshot.getValue(Box.class).getName());
}
// other callbacks
}
There is a add button that I used to push new records from Android to Firebase
.
final Button button = (Button) findViewById(R.id.addButton);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Box box = new Box("Box " + System.currentTimeMillis(), "Location " + System.currentTimeMillis());
Firebase fbBox = firebase.child("" + System.currentTimeMillis());
fbBox.setValue(box);
}
});
But above code doesn't add any record (evident from ListView
that is not updated) or atleast I might not know where to look for the data. I checked opening Firebase
in browser, but I am not sure how to check for user specific data?
I modified my Firebase Rules
like
{
"rules": {
"users": {
"$uid": {
".write": "auth != null && auth.uid == $uid",
".read": "auth != null && auth.uid == $uid"
}
}
}
}
I tried to open URLs such as https://xyz.firebaseio.com/xxxxxx-xxxxx-xxxx-xxxxx-xxxxxxxxxxxx but it wouldn't show any data.
I would like to have some information on:
How to add user specific data after authentication. Can't it be seamless like when we don't have any restriction on read/write on user basis, because I could easily read/write data.
Is there any
Firebase
web view to visualize the database or see JSON data, where I can see/modify the data to/from Android device?
For web end
Javascript code:
Read https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user for more information.
First, modify the Firebase rules as follows:
Then, in Java Code:
In the end, the data would look something like this: