0

Is there a way to notify the application directly if you delete a user from firebase using the firebase console? I have tried with an authlistener but the application does not notice the change in current user when I delete the user. I have to reinstall the application for the application to notice that there is no user anymore? Is there a way to solve this?

What I have tried

override fun getFirebaseAuthState() = callbackFlow {
    val authStateListener = FirebaseAuth.AuthStateListener { auth ->
        trySend(auth.currentUser == null)
    }
    auth.checkIfUserExists().addAuthStateListener(authStateListener)
       awaitClose {
         auth.checkIfUserExists().removeAuthStateListener(authStateListener)
       }
}

The viewModel calling it

   init {
        getAuthState()
    }


    fun getAuthState() = liveData{
        useCases.getAuthState().collect{response ->
            emit(response)
        }

    }
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
jens
  • 207
  • 2
  • 9
  • This code was inspired by this [article](https://medium.com/firebase-tips-tricks/how-to-handle-firebase-authentication-in-clean-architecture-using-jetpack-compose-e9929c0e31f8). However, it doesn't handle the case when you delete a user from the Firebase console. – Alex Mamo Feb 10 '22 at 07:06

1 Answers1

1

The authentication state on the client is based on an ID token, that is valid for one hour and automatically refreshed by the SDK. When you delete (or disable) the user, the client can no longer refresh the ID token, but its current ID token will be valid for up to an hour.

You can force the client to try and refresh its token before that, but Firebase has no built-in way to immediately notify the client of the (so-called out-of-band) user deletion.

If you want to mark the user's ID token is having become invalid, have a look at the Firebase documentation on ID token revocation or one of these questions:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807