在updateEmail方法之前,我还使用了重新认证方法。一切正常。甚至updateEmail中的Toast消息也按预期显示,但用户的Firebase数据库中没有更改。
但是它仍然不会更改Firebase数据库中的电子邮件。
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
.getCredential(mAuth.getCurrentUser().getEmail(), password);
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User re-authenticated.");
mAuth.fetchSignInMethodsForEmail(email.getText().toString()).addOnCompleteListener(new OnCompleteListener<SignInMethodQueryResult>() {
@Override
public void onComplete(@NonNull Task<SignInMethodQueryResult> task) {
if (task.isSuccessful()) {
try {
if (task.getResult().getSignInMethods().size() == 1) {
Log.d(TAG, "onComplete: This will return the signin methods");
Toast.makeText(getActivity(), "The email is already exist", Toast.LENGTH_SHORT).show();
}else{
Log.d(TAG, "onComplete: Email is not present. User can change it");
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.updateEmail(email.getText().toString())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated.");
Toast.makeText(getActivity(), "The email updated.", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch(NullPointerException e) {
Log.e(TAG, "onComplete: NullPointerException" + e.getMessage());
}
}
}
});
} else {
Log.d(TAG, "onComplete: User re-authentication failed.");
}
}
});
答案 0 :(得分:0)
此mAuth.getCurrentUser().getEmail()
将为您提供来自Firebase内置用户类的电子邮件,而不是数据库本身的电子邮件。
我看不到您在数据库本身中更改电子邮件的任何方式。
此功能更新Firebase用户类中的电子邮件,可以在Firebase控制台的“身份验证”部分中看到
user.updateEmail(email.getText().toString())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated.");
Toast.makeText(getActivity(), "The email updated.", Toast.LENGTH_SHORT).show();
}
}
});
要更新数据库中的数据,您必须遵循this
我再一次重复您要更新Firebase用户类中的用户电子邮件,而不是实际数据库。如上所述,更新的电子邮件仅在Firebase控制台的“身份验证”部分中可见,并且要在“数据库”中进行数据更改,您必须单击链接。