【问题标题】:adding extra profile information in FirebaseAuth android在 FirebaseAuth android 中添加额外的个人资料信息
【发布时间】:2019-11-23 08:33:38
【问题描述】:

我想向 FirebaseAuth 用户配置文件添加额外的配置文件信息,有一个如下所示的更新配置文件方法,我想添加额外的信息,例如:UserId,是否可以这样做?

val profileUpdates = UserProfileChangeRequest.Builder()
                .setDisplayName(usernameEditText.text.toString())
                .build()

【问题讨论】:

标签: java android firebase kotlin firebase-authentication


【解决方案1】:

如果您在 Firebase 身份验证中创建了用户,那么您将获得以下信息:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
    for (UserInfo profile : user.getProviderData()) {
        // Id of the provider (ex: google.com)
        String providerId = profile.getProviderId();

        // UID specific to the provider
        String uid = profile.getUid();

        // Name, email address, and profile photo Url
        String name = profile.getDisplayName();
        String email = profile.getEmail();
        Uri photoUrl = profile.getPhotoUrl();
    }
}

关于更新个人资料,您可以更新显示名称和照片网址:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
        .setDisplayName("Jane Q. User")
        .setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
        .build();

user.updateProfile(profileUpdates)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task) {
                if (task.isSuccessful()) {
                    Log.d(TAG, "User profile updated.");
                }
            }
        });

您无法更新uid,如果您想添加更多与用户相关的数据,那么唯一的选择就是同时使用数据库和身份验证。

您可以查看文档以获取更多信息:

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

【讨论】:

    猜你喜欢
    • 2018-04-26
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 2017-11-11
    • 1970-01-01
    • 2012-04-20
    • 2013-05-06
    • 1970-01-01
    相关资源
    最近更新 更多