Google Firebase sign out and forget user in Android app
In the Firebase Auth Quickstart sample code, the sign-out for Google provider includes these steps. Are you calling GoogleSignInClient.signOut()
when you sign-out?
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);
}
});
}
Google Firebase sign out and forget google account
How do you forget/sign out a Google account, so another google account can sign in?
To sign-out a Google account, please use the following lines of code:
GoogleSignInOptions options = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(application.getString(R.string.default_web_client_id))
.requestEmail()
.build();
GoogleSignInClient googleClient = GoogleSignIn.getClient(application, options);
googleClient.signOut();
If you are interested in a clean Firebase authentication with Google, you can check the following article:
- How to create a clean Firebase authentication using MVVM?.
Firebase Google auth, signing out and logging in again will log in with the last signed account
this is what I did to log out.
FirebaseAuth.getInstance().signOut();
When you try to sign out using the above line of code, it basically means that you are signing out only from Firebase.
I am using Firebase Google Auth, signing out and logging in again will log in with the last signed account. How can I make it show the "choose account" dialog?
As I see, you are using Google authentication. Signing out from Firebase doesn't mean that you are automatically signed out from Google. It doesn't. To sign out from Google you have to explicitly add a call to GoogleSignInClient#signOut() method, like this:
googleSignInClient.signOut();
Please don't forget that the sign-out operation is asynchronous, meaning that you have to wait until the operation completes, which may take some time. Since this method returns an object of type Task, you can use addOnCompleteListener(OnCompleteListener listener) method, to know when you are completely signed out.
Properly log out a user from android app
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.
A properly implemented flow would not automatically re-authenticate them when the user presses the back button, but that depends on the flow you implement (which is missing from your question and would likely be too much code anyway).
Sign out from Google Account using Firebase Authentication
When you use AuthUI you don't need to sign out with GoogleSignInClient. You can do it from directly AuthUI like:
AuthUI.getInstance()
.signOut(context)
.addOnSuccessListener { // start login activity }
User is always signed in and can't logout in flutter firebase
Apparently the problem wasn't with firebase but with the custom button I had built. I didn't assign the onPressed properly and the logout button wasn't working because of that.
How to remove the access rights to a linked google account after the deletion of an account at firebase?
If you have implemented the option to sign in your users to Firebase with Google, then most likely you already have followed these steps:
- Authenticate with Google on Android
- Get started with One Tap sign-in and sign-up
According to:
I just implemented the possibility to delete the personal account at Firebase of an Android application.
If you have only deleted the Firebase authentication account it doesn't mean that everything related to Google is wiped out, because it's not.
To achieve what you want, I recommend you follow the below steps in the exact order I have added:
- Sign-out the user from Google using SignInClient#signOut() method.
Signs out the currently signed-in user if any.
- Delete the Firebase user account using FirebaseUser#delete() method:
Deletes the user record from your Firebase project's database. If the operation is successful, the user will be signed out.
- Delete all data in Cloud Firestore using DocumentReference#delete(), or the Realtime Database using DatabaseReference#removeValue(), if it exists.
So in the case of 2. there is no need to explicitly sign out the user from Firebase because when you delete the account, the user will be signed out automatically.
P.S. Please also remember that all three operations are asynchronous. So you need to wait until the operations are complete. In java, you can use a LiveData object and in Kotlin you can use Kotlin Coroutines.
Edit:
Regarding FirebaseUser#unlink(String provider) method, it only:
Detaches credentials from a given provider type from this user.
I have even written an article regarding this topic:
- How to authenticate to Firebase using Google One Tap in Jetpack Compose?
Related Topics
Android How to Apply Mask on Imageview
Android Countdowntimer - Additional Milliseconds Delay Between Ticks
How to Create Preference Activity and Preference Fragment on Android
Error Importing Holoeverywhere
Ionic Build Android | Error: No Installed Build Tools Found. Please Install the Android Build Tools
Check If Correct Google Play Service Available: "Unfortunately Application Has Stopped Working"
Android Gradle Apache Httpclient Does Not Exist
Programmatically Adding Tablerow to Tablelayout Not Working
Simple Example for Intent and Bundle
A Way to Get Unlock Event in Android
Fragmentcontainerview Using Findnavcontroller
Creating Tabs Using Fragments Now That Tabactivity Is Deprecated
Coupling Firebaserecyclerviewadapter to a Boolean/String Map.Entry
Place 2 Textview Beside Each Other with 2Nd Textview Always Visible
Android: How to Get Value of an Attribute in Code
Complete Working Sample of the Gmail Three-Fragment Animation Scenario