Can I allow a user to make a custom username at the time of Registration if they use Google/Facebook sign in?

后端 未结 2 1728
花落未央
花落未央 2021-01-26 10:05

I just implemented Firebase authUI in an app but I\'d like my users to be able to have usernames/display names that aren\'t their names on those accounts, without f

2条回答
  •  死守一世寂寞
    2021-01-26 10:40

    Yes you can. As @Gastón Saillén mentioned in his answer, when you first sing-in, you get the data from the registration provider but once you are signed in with Firebase, you can set a custom user name by updating the existing one using UserProfileChangeRequest.Builder.setDisplayName() method like this:

    FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
    UserProfileChangeRequest userProfileChangeRequest = new UserProfileChangeRequest.Builder()
            .setDisplayName("aedgar777")
            .build();
    
    firebaseUser.updateProfile(userProfileChangeRequest).addOnCompleteListener(new OnCompleteListener() {
        @Override
        public void onComplete(@NonNull Task task) {
            if (task.isSuccessful()) {
                Log.d(TAG, "aedgar777 updated!");
            }
        }
    });
    

提交回复
热议问题