Home > Net >  notify application directly when you delete a user in the firebase console?
notify application directly when you delete a user in the firebase console?

Time:02-10

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)
        }

    }

CodePudding user response:

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:

  •  Tags:  
  • Related