1

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

2

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.

Abdul Mahamaliyev
  • 750
  • 1
  • 8
  • 20
Jay
  • 34,438
  • 18
  • 52
  • 81