skip to Main Content

I have built an auth gateway in which users can log in through a Google account. I have 2 Google accounts now on my device but whenever I try to sign in, it is getting sign-in through the default account that I have signed in through first.

Initially, I’m making users sign out through mAuth.signOut() but it is only signing out users through Firebase, I want to do it for Google accounts.

2

Answers


  1. When you implement Firebase Authentication with Google, there are two operations that you need to perform. The first one is to authenticate the user in Google, and once you have successfully done that, you grab the credentials and then authenticate in Firebase. So it’s a two-step operation. On the other hand, when you sign the user out, you have to do the same, sign the user out from Google and then from Firebase. If you’re using Firebase Authentication with Google using OneTap, then to sign the user out from Google you have to use SignInClient#signOut() and to sign out from Firebase, FirebaseAuth#signOut().

    If you don’t sign the user out from Google, when you try to reauthenticate the user, the user will be already signed in to Google, that is the reason why you have the behavior. So you have to sign out from bith.

    Login or Signup to reply.
  2. To allow user to choose a Google account from the list everytime they login, you need to call revokeAccess() on GoogleSignInClient object before using it & that’s it. Your problem will be solved.

    GoogleSignInOptions gso =
         new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
         .requestIdToken(clientId)
         .requestEmail()
         .setAccountName(emailAddress)
         .build();
    
     GoogleSignInClient signinClient = GoogleSignIn.getClient(context, gso);
     signInClient.revokeAccess();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search