How to save user's name along with email in firebase? [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-12 03:26:56

问题


Firebase saves only email of the user. I want to save his/her name too.

How to achieve this?

Here's a bit of my code with which I'm creating and logging in the user:

public void loginByEmailMethod() {
        //creating account
        ref.createUser(email, password, new Firebase.ValueResultHandler<Map<String, Object>>() {
            @Override
            public void onSuccess(Map<String, Object> result) {
                System.out.println("Successfully created user account with uid: " + result.get("uid"));
                Toast.makeText(getBaseContext(), "Account successfully created!", Toast.LENGTH_LONG).show();
            }

            @Override
            public void onError(FirebaseError firebaseError) {
                // there was an error
                Toast.makeText(getBaseContext(), "Account not created!", Toast.LENGTH_LONG).show();
            }
        });

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                //logging in the user
                ref.authWithPassword(email, password, new Firebase.AuthResultHandler() {
                    @Override
                    public void onAuthenticated(AuthData authData) {
                        System.out.println("User ID: " + authData.getUid() + ", Provider: " + authData.getProvider());
                        Intent mainActivityIntent = new Intent(SignupScreenActivity.this, MainActivity.class);
                        startActivity(mainActivityIntent);

                        Toast.makeText(getBaseContext(), "User logged in successfully!", Toast.LENGTH_LONG).show();

                    }

                    @Override
                    public void onAuthenticationError(FirebaseError firebaseError) {
                        // there was an error
                        Toast.makeText(getBaseContext(), "User not logged in!", Toast.LENGTH_LONG).show();
                        progressDialog.dismiss();
                    }
                });
            }
        }, 2000);
    }

The problem is that with this method I can save only the email address of the user and not his/her name.

Please let me know how can I save name along with the email.

Thanks in advance.


回答1:


You would typically want to store any additional user information in a /users node.

Like this

uid
  name: "Ted"
  fav_movie "Airplane"
  position: "Sitting front facing forward"

The uid was the user id created when you created the user in Firebase.

This is a very common design pattern in Firebase and there's a super terrific example in their User Authentication guide.

About 1/2 way down in the Storing User Data section is what you want to review.



来源:https://stackoverflow.com/questions/36224004/how-to-save-users-name-along-with-email-in-firebase

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