Google Firebase 在 Android 应用中注销并忘记用户 [英] Google Firebase sign out and forget user in Android app
问题描述
当我调用 mFirebaseAuth.signOut()
或 mFirebaseUser.delete()
时,我的 FirebaseAuth.AuthStateListener()
工作正常并返回 null
作为 onAuthStateChanged
中的 FirebaseUser
实例,我刷新 UI 并显示使用 Google 登录"按钮.
When I call mFirebaseAuth.signOut()
or mFirebaseUser.delete()
my FirebaseAuth.AuthStateListener()
works correctly and returns null
as FirebaseUser
instance in onAuthStateChanged
, I refresh UI and show "Sign in with Google" button.
但是当我想再次登录时,我没有看到与用户的对话框(我的设备上有 2 个用户,附上图片).该应用程序仅在第一次登录时显示此对话框,之后它会使用相同的用户.如果我在设置屏幕上清除应用程序的数据,我将能够再次看到此对话框.
But when I want to log in again, I don't see the dialog with users (I have 2 users on my device, attached the image). The app shows this dialog only in first sign in, after that it uses the same user. If I clear app's data on the settings screen I will be able to see this dialog again.
我的问题是如何在每次注销后显示此对话框.
My question is how to show this dialog after every sign out.
我在按下登录"按钮时运行此代码:
I run this code when press Sign In button:
// in onCreate()
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
// in OnClickListener
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, FirebaseActivity.REQUEST_SIGN_IN);
在 onActivityResult()
中,我得到了一个 GoogleSignInResult
的实例,所以我需要的一切都在我调用 startActivityForResult()
之后发生.
In onActivityResult()
, I get an instance of GoogleSignInResult
so everything I need happens after I call startActivityForResult()
.
推荐答案
在 Firebase Auth Quickstart 示例代码,Google 提供商的注销包括这些步骤.您在退出时是否调用了 GoogleSignInClient.signOut()
?
In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut()
when you sign-out?
private void signOut() {
// Firebase sign out
mAuth.signOut();
// Google sign out
mGoogleSignInClient.signOut().addOnCompleteListener(this,
new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
updateUI(null);
}
});
}
这篇关于Google Firebase 在 Android 应用中注销并忘记用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!