How to force google account chooser after sign out in android firebase auth

后端 未结 1 1079
夕颜
夕颜 2021-01-12 11:23

I am using Firebase Google Auth, signing out and logging in again will log in with last signed account. How can I make account chooser every time?

相关标签:
1条回答
  • 2021-01-12 11:52

    Firebase Auth Quickstart sample code provides the following few steps for sign out

    Declare Globally these two variables

    private GoogleSignInClient mGoogleSignInClient;
    private GoogleSignInOptions gso;
    

    Add these lines in onCreate method

    gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
    
    

    Now for signOut

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

    It's easy, and it will work. Cheers!

    0 讨论(0)
提交回复
热议问题