Как связать существующую учетную запись пользователя с разными провайдерами, но с одним и тем же адресом электронной почты? Например, Google с Facebook.
public void handleFacebookAccessToken(final AccessToken token, final Activity activity) {
Log.d(TAG, "handleFacebookAccessToken: " + token);
final AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
authListener.updateSignedUI(user);
}
}
}).addOnFailureListener(activity, new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "signInWithCredential:failure", e);
if (e instanceof FirebaseAuthUserCollisionException) {
handleLinkingFacebookUsers(credential, activity);
}
}
});
}
В этом методе ниже в строке с ' mAuth.getCurrentUser (). linkWithCredential () Возникновение NullPointerException.
private void handleLinkingFacebookUsers(AuthCredential savedFBCredential, Activity activity) {
//AuthCredential credentialFacebook = FacebookAuthProvider.getCredential(token.getToken());
//AuthCredential credentialGoogle = GoogleAuthProvider.getCredential(googleIdToken, null);
mAuth.getCurrentUser()
.linkWithCredential(savedFBCredential) // THIS LINE TROWS NULL POINTER EXCEPTION
.addOnCompleteListener(activity, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "linkWithCredential:success");
FirebaseUser user = task.getResult().getUser();
authListener.updateSignedUI(user);
} else {
Log.w(TAG, "linkWithCredential:failure", task.getException());
authListener.updateSignedUI(null);
}
// ...
}
});
}
Logcat:
com.google.firebase.auth.FirebaseAuthUserCollisionException: An account already exists with the same email address but different sign-in credentials. Sign in using a provider associated with this email address.
at com.google.firebase.auth.api.internal.zzdv.zza(com.google.firebase:firebase-auth@@19.2.0:42)
at com.google.firebase.auth.api.internal.zzfc.zza(com.google.firebase:firebase-auth@@19.2.0:19)
at com.google.firebase.auth.api.internal.zzes.zza(com.google.firebase:firebase-auth@@19.2.0:34)
at com.google.firebase.auth.api.internal.zzeu.zza(com.google.firebase:firebase-auth@@19.2.0:98)
at com.google.firebase.auth.api.internal.zzeu.zza(com.google.firebase:firebase-auth@@19.2.0:85)
Любое предложение ценится. Спасибо.