如果他们使用Google/Facebook登录,我可以允许用户在注册时创建自定义用户名吗? [英] Can I allow a user to make a custom username at the time of Registration if they use Google/Facebook sign in?

查看:78
本文介绍了如果他们使用Google/Facebook登录,我可以允许用户在注册时创建自定义用户名吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在应用程序中实现了Firebase authUI,但是我希望我的用户能够拥有不是这些帐户名称的用户名/显示名称,而又不必稍后再更改.如果可能,我将在哪里以及如何实施?

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 forcing them to change later. If possible, where and how would I implement this?

推荐答案

可以.就像@GastónSaillén在他的回答中提到的那样,当您第一次唱歌时,您是从注册提供商那里获得数据的,但是一旦您使用Firebase登录,您就可以通过使用 UserProfileChangeRequest.Builder .setDisplayName()方法如下:

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<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        if (task.isSuccessful()) {
            Log.d(TAG, "aedgar777 updated!");
        }
    }
});

这篇关于如果他们使用Google/Facebook登录,我可以允许用户在注册时创建自定义用户名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆