2

I have begin to use Firebase but my experience is terrible.

I cannot sign out user.

I have tried different things and spend all my 4 days to figure out how to sign out user but there is not clear option.

I want to sing out user totally so they can select another gmail account .

I have tried below code:

FirebaseUser user = firebaseAuth.getCurrentUser();
user.unlink(user.getProviderId()); FirebaseAuth.getInstance().signOut();

inside of

mAuth = FirebaseAuth.getInstance();//mAuth.signOut();
        //auth fail olarsa mAuth.signOut(); sil sonra yerne qoy
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {

I have tried also this:Properly log out a user from android app

3 Answers3

1

If you check the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps.

Are you calling Auth.GoogleSignInApi.signOut() when you sign-out? So, please use this code:

private void signOut() {
    // Firebase sign out
    mAuth.signOut();

    // Google sign out
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
        new ResultCallback<Status>() {
            @Override
            public void onResult(@NonNull Status status) {
                //do what you want
            }
        });
}
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • The current documentation for Google Sign-In states `To sign out a user, call signOut: FirebaseAuth.getInstance().signOut();`https://firebase.google.com/docs/auth/android/google-signin – androidguy Aug 07 '17 at 18:01
  • java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.Context com.google.android.gms.common.api.GoogleApiClient.getContext() it gave error and I have tried it before – Alex Robertson Aug 07 '17 at 18:19
  • @user3175580 it is not enough because user cannot sign in with another account – Alex Robertson Aug 07 '17 at 18:20
  • @AlexAlex but using just this method I am able to view the email list again after clicking the Google button in my login activity. What version is your firebase auth dependency? – androidguy Aug 07 '17 at 18:23
  • compile 'com.google.android.gms:play-services:11.0.4' compile 'com.google.firebase:firebase-database:11.0.4' compile 'com.google.firebase:firebase-auth:11.0.4' compile 'com.google.android.gms:play-services-auth:11.0.4' i – Alex Robertson Aug 07 '17 at 18:26
  • @user3175580 11.0.4 – Alex Robertson Aug 07 '17 at 18:26
0

You are using a newer version than me, I doubt they introduced a new bug. You mentioned NullPointerException earlier, so I suggest you make sure the GoogleApiClient you pass to Auth.GoogleSignInApi.getSignInIntent is not null.

androidguy
  • 3,005
  • 2
  • 27
  • 38
  • Yeah I have tried it also , and got not connected error then I have tried to put it to button click listener so it will have time to connect , and it worked!!!!!!! – Alex Robertson Aug 07 '17 at 20:22
-1

I also have this problem, right now, the LogoutBtn is inside a drawer, like this:

case R.id.initiates_logout:
            if(FirebaseAuth.getInstance().getCurrentUser()!=null){
                new AlertDialog.Builder(this)
                        .setTitle("Text1")
                        .setMessage("Text2")
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                FirebaseAuth.getInstance().signOut();
                                LoginManager.getInstance().logOut();


                            }})
                        .setNegativeButton(android.R.string.no, null).show();
            }
            break;

And i cant select another account after the logout.