我想向 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/