MarkOSullivan94 MarkOSullivan94 - 16 days ago 6
Android Question

Storing user data example - display name not showing in database

A bit confused why there's no display name being displayed in my Firebase database, I've followed the steps in the example on their website and didn't get the expected result which they showed. Here's the example code.

final Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithPassword("jenny@example.com", "correcthorsebatterystaple",
new Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
// Authentication just completed successfully :)
Map<String, String> map = new HashMap<String, String>();
map.put("provider", authData.getProvider());
if(authData.getProviderData().containsKey("displayName")) {
map.put("displayName", authData.getProviderData().get("displayName").toString());
}
ref.child("users").child(authData.getUid()).setValue(map);
}
@Override
public void onAuthenticationError(FirebaseError error) {
// Something went wrong :(
}
});


Whenever I tried this example code the expected result was to be something similar to what is shown below.

{
"users": {
"6d914336-d254-4fdb-8520-68b740e047e4": {
"displayName": "alanisawesome",
"provider": "password"
},
"002a448c-30c0-4b87-a16b-f70dfebe3386": {
"displayName": "gracehop",
"provider": "password"
}
}
}


Instead of showing something similar to the above, in my database only the provider is shown and not the displayName. Is there any necessary steps required to get the displayName to show or should it be there automatically?

I tried to look into this to see what was included within
authData.getProviderData()
and this was what was produced in the console when I printed it out.

01-25 17:58:51.921 15651-15651/<package-name> I/System.out: {email=j.joe@hotmail.co.uk, isTemporaryPassword=false, profileImageURL=https://secure.gravatar.com/avatar/de53da9874178adb1a44b392ba5bed2f?d=retro}


So from the result produced it's left me wondering if the key "displayName" was formerly automatically created from the email and stored by default in
authData.getProviderData()
and that's why it is no longer shown.

Would appreciate it if someone could explain where the displayName in the database comes from because judging by the expected result it seems I've missed something.

Thanks!

Answer

An email+password account does not have an associated display name. It only requires an email address and a password.

You can definitely require the user to enter additional information. Just don't pass it to createUser() and don't overwrite it after calling authWithPassword().

Update: since the update to Firebase Authentication released at Google I/O 2016, there is now a display name property for each user. So you can also keep the display name in Firebase Authentication itself (although you won't be able to query/search for it).

Comments