没有在Firebase身份验证中找到使用Google登录的用户记录。

huangapple 未分类评论51阅读模式
标题翻译

No user records in Firebase authentication with Google sign in

问题

这段代码在我通过 Google 账号登录时显示登录成功,但是在我的 Firebase 中没有任何用户记录。

if (requestCode == RC_SIGN_IN) {
    GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
    if(result.isSuccess()){
        GoogleSignInAccount account = result.getSignInAccount();
        firebaseAuthWithGoogle(account);
        Toast.makeText(this,"成功使用 Google 登录",Toast.LENGTH_SHORT).show();
        startActivity(new Intent(MainActivity.this, SecondActivity.class));
    }
    else
        Toast.makeText(this,"使用 Google 登录失败",Toast.LENGTH_SHORT).show();
}
private void firebaseAuthWithGoogle(GoogleSignInAccount idToken) {
    AuthCredential credential = GoogleAuthProvider.getCredential(String.valueOf(idToken), null);
    firebaseAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "signInWithCredential:success");
                        Toast.makeText(MainActivity.this,"成功加载到数据库",Toast.LENGTH_SHORT).show();
                    } else {
                        Log.w(TAG, "signInWithCredential:failure", task.getException());
                    }
                }
            });
}

我以为 firebaseAuth.signInWithCredential(credential) 会导致用户数据保存到列表中?

图片描述

英文翻译

It shows successful when I login via google account but there's no any user records in my firebase.

            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if(result.isSuccess()){
                GoogleSignInAccount account = result.getSignInAccount();
                firebaseAuthWithGoogle(account);
                Toast.makeText(this,&quot;Sign in with Google successfully&quot;,Toast.LENGTH_SHORT).show();
                startActivity(new Intent(MainActivity.this, SecondActivity.class));
            }
            else
                Toast.makeText(this,&quot;Sign in with Google failed&quot;,Toast.LENGTH_SHORT).show();
        }
private void firebaseAuthWithGoogle(GoogleSignInAccount idToken) {
        AuthCredential credential = GoogleAuthProvider.getCredential(String.valueOf(idToken), null);
        firebaseAuth.signInWithCredential(credential)
                .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                    @Override
                    public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                        if (task.isSuccessful()) {
                            Log.d(TAG, &quot;signInWithCredential:success&quot;);
                            Toast.makeText(MainActivity.this,&quot;load into database successfully&quot;,Toast.LENGTH_SHORT).show();
                        } else {
                            Log.w(TAG, &quot;signInWithCredential:failure&quot;, task.getException());
                        }
                    }
                });
    }

I thought firebaseAuth.signInWithCredential(credential) will cause users' data save into the list?

Image Description

huangapple
  • 本文由 发表于 2020年5月31日 00:03:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/62105105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定