0

I want to add some extra flied to user when he signup, the method does not let me do it. I want to add username, city, phone, as extra parameter

public class SignupActivity extends AppCompatActivity {

private EditText inputEmail, inputPassword,inputUserName,inputCity,inputPhone_Num;
private Button btnSignIn, btnSignUp, btnResetPassword;
private ProgressBar progressBar;
private FirebaseAuth auth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);

    //Get Firebase auth instance
    auth = FirebaseAuth.getInstance();

    btnSignIn = (Button) findViewById(R.id.sign_in_button);
    btnSignUp = (Button) findViewById(R.id.sign_up_button);
    inputUserName = (EditText) findViewById(R.id.username);
    inputCity = (EditText) findViewById(R.id.city);
    inputPhone_Num = (EditText) findViewById(R.id.phone);
    inputEmail = (EditText) findViewById(R.id.email);
    inputPassword = (EditText) findViewById(R.id.password);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    btnResetPassword = (Button) findViewById(R.id.btn_reset_password);

    btnResetPassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(SignupActivity.this, ResetPasswordActivity.class));
        }
    });

    btnSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    btnSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String username = inputUserName.getText().toString().trim();
            String city = inputCity.getText().toString().trim();
            String phone = inputPhone_Num.getText().toString().trim();
            String email = inputEmail.getText().toString().trim();
            String password = inputPassword.getText().toString().trim();

            if (TextUtils.isEmpty(username)) {
                Toast.makeText(getApplicationContext(), "Enter username address!", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(city)) {
                Toast.makeText(getApplicationContext(), "Enter city address!", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(phone)) {
                Toast.makeText(getApplicationContext(), "Enter phone numer address!", Toast.LENGTH_SHORT).show();
                return;
            }
            if (TextUtils.isEmpty(email)) {
                Toast.makeText(getApplicationContext(), "Enter email address!", Toast.LENGTH_SHORT).show();
                return;
            }

            if (TextUtils.isEmpty(password)) {
                Toast.makeText(getApplicationContext(), "Enter password!", Toast.LENGTH_SHORT).show();
                return;
            }

            if (password.length() < 6) {
                Toast.makeText(getApplicationContext(), "Password too short, enter minimum 6 characters!", Toast.LENGTH_SHORT).show();
                return;
            }

            progressBar.setVisibility(View.VISIBLE);

here I want to add username, city, phone, as extra parameter

            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 {
                                startActivity(new Intent(SignupActivity.this, ProfileActivity.class));
                                finish();
                            }
                        }
                    });

        }
    });
}

@Override
protected void onResume() {
    super.onResume();
    progressBar.setVisibility(View.GONE);
}
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • If you want to store data beyond the built-in properties that Firebase Authentication supports, you'll have to store them in a separate database. Typically developers use one of the Firebase databases (Realtime Database, or Firestore) for this. See https://stackoverflow.com/a/37420701, https://stackoverflow.com/a/39192650, https://stackoverflow.com/a/43445277 – Frank van Puffelen Dec 25 '19 at 16:47
  • @mohammmeden If the answer helped you please upvote it, I would appreciate it, thank you! – Peter Haddad Dec 27 '19 at 13:19

1 Answers1

0

If you want to add username/City/address then you need to use your own implementation. The method createuserwithEmailAndPassword adds a user to the Firebase authentication console. Also it will give you a unique ID for each user. Please check the following:

https://firebase.google.com/docs/auth/android/manage-users

If you want to add those extra info, then it is better to use firebase database with firebase authentication.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134