标题翻译
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,"Sign in with Google successfully",Toast.LENGTH_SHORT).show();
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
else
Toast.makeText(this,"Sign in with Google failed",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,"load into database successfully",Toast.LENGTH_SHORT).show();
} else {
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
}
});
}
I thought firebaseAuth.signInWithCredential(credential) will cause users' data save into the list?
专注分享java语言的经验与见解,让所有开发者获益!
评论