Google Firebase sign out and forget user in Android app

GrafOrlov picture GrafOrlov · Aug 1, 2016 · Viewed 29.4k times · Source

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.

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.

enter image description here

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

In onActivityResult(), I get an instance of GoogleSignInResult so everything I need happens after I call startActivityForResult().

Answer

Bob Snyder picture Bob Snyder · Aug 1, 2016

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