0

I'm using the following steps to sign-up a new Firebase user. Is there a way for me to set a username parameter so in the future the user can login using a username & password ?

Also, is there a way to sign up only using a username & password ,ie, I would not like to have an option of e-mail ID.

I've gone through the following solution, but it doesn't seem efficient. I suppose there is a better way of doing so.

Firebase login and signup with username

    private FirebaseAuth auth;

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


   //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();
                                // 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, MainActivity.class));
                                    finish();
                                }
                            }
                        });
Community
  • 1
  • 1
Zen
  • 2,698
  • 4
  • 28
  • 41

2 Answers2

0

You can add any domain behind the username

register your user with < username > @summersApp.com.

Note that this will make it impossible to for the user to reset their password if they forget it, since Firebase uses the email address to send the password reset email.

Nirel
  • 1,855
  • 1
  • 15
  • 26
  • Yep. That was my main concern. Also, any way of adding additional parameters to user class? Like no.of posts? no.of friends etc? – Zen Nov 07 '16 at 14:12
  • Save all details about users at /users/uid – Nirel Nov 07 '16 at 14:28
0

To answer OP's question in comments above,

To save extra information to a user, link a reference in the database to their UID as shown here

Example:

/users
  /uid1
    no.of.posts: 3,
    no.of.friends: 4
  /uid2
    no.of.posts: 5,
    no.of.friends: 6
  /uid3
    no.of.posts: 7,
    no.of.friends: 8