如何验证用户是否已注册?
private void firebaseAuthWithGoogle(final GoogleSignInAccount acct, final GoogleSignInResult result) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
//HOW CAN I validate user is already signup or not
if (Singup == true) {
did not create account.
} else {
create account;
}
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(Login.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
// updateUI(null);
}
}
});
}
这是在用户已经存在或不存在时创建帐户。
答案 0 :(得分:0)
您需要拥有FirebaseAuth
的实例。然后在if (task.isSuccessful()) {...}
块中,使用FirebaseUser
获取FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
的实例。
之后你可以替换
if (Singup == true) {
// did not create account.
} else {
// create account;
}
与
if (firebaseUser == null) {
// did not create account.
} else {
// create account;
}
可以在lines 137 and 197 sample和here (Firebase google sigin doc)
上找到更多详情