1

im struggling while im coding my first app on android device using Android Studio. I used Firebase for the auth. I follow every steps, and my app doing well while logging in and logging out.

The problem is that the first time i press on login, a popup let me choose which google account i can use. But after that, when i log out and try to login again, the app connect automatically with the first account we chosen and i cant choose another account again.

I notice that if i go into my phone and clear cache and data about the app, now i can choose which google account use for the app.

I google really much through the internet and found this one

Google Firebase sign out and forget user in Android app

But over there they talk about some "googleapiclient" or "Auth.GoogleSignInApi.signOut(mGoogleApiClient)".

But in the tutorial i see no variables named mGoogleApiClient, so i thought that maybe that was okay for a old version, and im now working on a new version?

I really struggle a lot. I dunno where to search, i dunno where im wrong.

How can i logout from my app and then, when i press login, be able to choose again and again a different account? Please help, thx a lot.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
mosenco
  • 83
  • 6

2 Answers2

1

If you are using Firebase with Google/Facebook/Twitter accounts to sign out of the app you'll just need to make a call to:

// Kotlin sample for java just add semicolon ;)
FirebaseAuth.getInstance().signOut()

Source: https://firebase.google.com/docs/auth/android/google-signin

Patty P
  • 351
  • 2
  • 12
  • 2
    yes, i did already, but when i press the button to login, i got connected with the same account and cant choose another one – mosenco Oct 11 '18 at 17:35
1

When Firebase authenticates the user (or you authenticate the user with Firebase), it stores the token for that user in local storage on your device.

This happens when you call one of the authWith... methods (of course only if it successfully authenticates the user).

Calling ref.unauth(); immediately deletes that token from local storage.

Also, to sign out simply, you can use:

FirebaseAuth.getInstance().signOut();
PradyumanDixit
  • 2,372
  • 2
  • 12
  • 20
  • i dont understand ref.unauth(), ref is a variable? i tried to put ref.unauth(); into my code but it gives me error. Can u show me an example? – mosenco Oct 11 '18 at 11:23
  • `ref` is the reference to the variable that references to current user, it was used dominantly in Firebase 2.x, nowadays the `...signOut()` will do the work. – PradyumanDixit Oct 11 '18 at 11:35
  • are u saying that signout() is enough to delete the token from local storage and disconnect the user? Because i already use it, and when i loggin back with the google button, it doesnt let me choose another account and keep loggin with the same user – mosenco Oct 11 '18 at 17:37