在我的 firebase 仪表板中我设置了multiple accounts for one email
option.
我的应用程序中有简单的电子邮件、Facebook 和 Google Plus 身份验证。
我在 LoginActivity 中这样处理它们:
谷歌加:
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
dialog.dismiss();
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
proceed();
} else {
// If sign in fails, display a message to the user.
Toast.makeText(LoginActivity.this, task.getException().getMessage(),
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
Facebook:
private void handleFacebookAccessToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
dialog.show();
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
dialog.dismiss();
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
FirebaseUser user = mAuth.getCurrentUser();
proceed();
} else {
Toast.makeText(LoginActivity.this, task.getException().getMessage(),
Toast.LENGTH_SHORT).show();
}
}
});
}
简单的电子邮件:
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
dialog.dismiss();
proceed();
} else {
Toast.makeText(LoginActivity.this, "Wrong email or password", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
}
});
现在我想让拥有相同 Facebook 和 Google Plus 电子邮件的用户能够使用 Facebook 和 Google Plus 进行授权。
This 本文档 https://firebase.google.com/docs/auth/android/account-linking文档说我应该跳过FirebaseAuth.signInWith
方法并调用这些函数:
AuthCredential credential = GoogleAuthProvider.getCredential(googleIdToken, null);
mAuth.getCurrentUser().linkWithCredential(credential)
现在很混乱。由于我跳过了signInWith方法,当getCurrentUser仍然为空时,我如何调用它?
文档还说我处理合并,但我不明白。
currentUser = auth.signInWithCredential(credential).await().getUser();
此外,signInWithCredential 没有await
method.
这意味着我应该在登录后使用同一电子邮件链接多个帐户?