我如何验证用户已注册?

时间:2017-10-17 23:18:43

标签: android firebase firebase-authentication

如何验证用户是否已注册?

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);
                    }
                }
            });
}

这是在用户已经存在或不存在时创建帐户。

1 个答案:

答案 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 samplehere (Firebase google sigin doc)

上找到更多详情
相关问题