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?
If signing in is successful, the developer console will log in our user. We can also click on the Google Signout button to logout from the app. The console will confirm that the logout was successful.
If you haven't yet connected your app to your Firebase project, do so from the Firebase console. Enable Email/Password sign-in: In the Firebase console, open the Auth section. On the Sign in method tab, enable the Email/password sign-in method and click Save.
If you'd like to sign the user out of their current authentication state, call the signOut method: import auth from '@react-native-firebase/auth'; auth() . signOut() .
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!
This part of Firebase Authentication with just a Google Sign In Button in place has given me a lot of nightmares, and if you have encountered the same issue, then I can assure that this answer will save you tons of hours!
Wherever you are implementing the Sign Out functionality, remember to use this line of code and you are good to go.
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.auth.api.signin.GoogleSignIn
GoogleSignIn.getClient(this, GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build())
.signOut()
This is a kotlin code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With