java - 在 FirebaseAuth android 中添加额外的个人资料信息

标签 java android firebase kotlin firebase-authentication

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

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

最佳答案

如果您在 Firebase Auth 中创建了一个用户,那么您将获得以下信息:

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

关于java - 在 FirebaseAuth android 中添加额外的个人资料信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57026198/

相关文章:

java excel 交互

android - Firebase 远程配置缓存在版本中的过期时间

android - 连接 VPN 时缺少 ConnectivityManager

java - getHostAddress() 返回反向的 ip 地址

javascript - 在 LoginService 中等待加载的用户数据

Firebase Firestore,查询用户好友的帖子

Java/HTML - 防止 outlook 在表格中包装文本

java - 为什么没有 java.lang.Array 类?如果java数组是一个Object,它不应该扩展Object吗?

java - 如何在junit中建立测试用例?

android - 免安装应用的 Firebase 支持库依赖冲突