Firebase how to get user details?

跟風遠走 提交于 2019-12-23 10:09:49

问题


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?


回答1:


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.




回答2:


//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();
            }
        }
    });
}
});



回答3:


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–



来源:https://stackoverflow.com/questions/38850700/firebase-how-to-get-user-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!