DyRight
DyRight

Reputation: 3

How to get an username for firebase android

I've created a Chat function on my android app, but I wanted my users to be able to create an account. However, I managed to let users create an account using Firebase. But the problem is that it allows you to create accounts with Facebook etc, I choose for email and password. This doesn't allow you to set an username, I believe so. Maybe there's a way to change the UID?

If anyone is able to help me out here, I'd be so thankful!

Again, I'm trying to let the user create an username too.

Upvotes: 0

Views: 1549

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598728

Have a look at the FirebaseUI implementation of its Email+Password registration flow:

firebaseAuth.createUserWithEmailAndPassword(email, password)
  .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
      if (task.isSuccessful()) {
        final FirebaseUser firebaseUser = task.getResult().getUser();
        Task<Void> updateTask = firebaseUser.updateProfile(
          new UserProfileChangeRequest
              .Builder()
              .setDisplayName(name).build());
        updateTask.addOnCompleteListener(new OnCompleteListener<Void>() {
          @Override
          public void onComplete(@NonNull Task<Void> task) {
            mActivityHelper.dismissDialog();
            if (task.isSuccessful()) {
              startSaveCredentials(firebaseUser, password);
            }
          }
        });
      }

Alternatively, you might simple want to use FirebaseUI, which encapsulates this and many other auth flows.

Upvotes: 2

Related Questions