7
votes

I am using Firebase authentication in my app and signing up a user with email and password. I want to get other users details (separate from the logged-in user) as well while a user is signed in with their own account. How can I get that information?

3
What do you mean by "other users details" ?Sistr
I want to get other user those are using my app for more specifically I want to get other user profile picture and name by using their UID or email or any other way without saving user details in firebase databaseFaris Jameel
There is no magic there. If the user login with a custom "email/password" you don't know anything else about that user (apart from the unique user id). If a user login with Facebook, or with Google sign in, you can get other information like the profile picture url. It is explained here: firebase.google.com/docs/auth/android/… . However if the user login only with a custom email/password, there is no magic, this fields will be empty.Sistr
As you noticed FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); this is only possible for current user "getCurrentUser()" is there any way like: FirebaseAuth.getInstance().getUser(UID);Faris Jameel
No there isn't, Harel below is right afaik.Sistr

3 Answers

2
votes

Values like email, display name and id (specific to authentication system) are available off of the Firebase User object. You can get a reference to the current logged in user off of the FIRAuth class. I provided links and class names for iOS, but other platforms are similarly structured.

If you want to store additional data for users, I would recommend including a users root node, using the uid off of the Firebase User object as the key for users child nodes.

-1
votes
//create user
auth.createUserWithEmailAndPassword(email, password)
    .addOnCompleteListener(SignupActivity.this, new OnCompleteListener < AuthResult > () {
        @Override
        public void onComplete(@NonNull Task < AuthResult > task) {
            Toast.makeText(SignupActivity.this, "createUserWithEmail:onComplete:" + task.isSuccessful(), Toast.LENGTH_SHORT).show();
            progressBar.setVisibility(View.GONE);
            // If sign in fails, display a message to the user. If sign in succeeds
            // the auth state listener will be notified and logic to handle the
            // signed in user can be handled in the listener.
            if (!task.isSuccessful()) {
                Toast.makeText(SignupActivity.this, "Authentication failed." + task.getException(),
                    Toast.LENGTH_SHORT).show();
            } else {
                String user_id = auth.getCurrentUser().getUid();
                DatabaseReference current_user_db = _Database.child(user_id);
                current_user_db.child("name").setValue(name);
                current_user_db.child("image").setValue("default");
                startActivity(new Intent(SignupActivity.this, ProfileActivity.class));
                finish();
            }
        }
    });
}
});
-2
votes

It's not a security issue, but just a mean of how you treat personal information. You can store what you want in firebase so you can easily store when the user login his/her avatar url (aka facebook url) or just id or any other infos anyway, then retrieve it. If you need to retrieve infos of users which are not using your apps beside, thden you can also easily via the facebook sdk with user permission of course. take care–