In the Firebase documentation on linking different authentication methods to the same user account, step 4 is confusing me. As I understand it, to login with a different auth provider, one would have to be logged out of the existing auth provider. However, how can we then call mAuth.getCurrentUser() to link the new auth with the existing one?
Step 4: Pass the AuthCredential object to the signed-in user's linkWithCredential method:
mAuth.getCurrentUser().linkWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "linkWithCredential(FB):success");
FirebaseUser currentUser = task.getResult().getUser();
login(currentUser);
} else {
Log.w(TAG, "linkWithCredential:failure", task.getException());
Toast.makeText(MainActivity.this, "Firebase Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
When I try run it as per the docs, I get a nullpointer exception, which is understandable because an instance of mAuth hasn't been created at this point.