I am integrating FirebaseAuth into an Android app that I am building. I have successfully integrated firebase into the app by adding the SDK, downloading and adding the google-services.json file.
The problem occurs when I try to Sign Up a new user. The user gets added to firebase console but I cannot retrieve the signed in user to update the name. This is the code from the fragment I am using it in.
requireActivity().let {
    val user = authenticationService.signUpWithEmailAndPassword(email, password)
    user?.let {
            authenticationService.updateUser(it, name)
            navigationService.openHomeScreen()//open next creen
    }
}
the signup function in the authenticationService
fun signUpWithEmailAndPassword(email: String, password: String): FirebaseUser? {
    signOutCurrentUser()
     firebaseAuth.createUserWithEmailAndPassword(email, password)
    return firebaseAuth.currentUser
}
the update user function
fun updateUser(user: FirebaseUser?, name: String) {
    val profileUpdates = UserProfileChangeRequest.Builder().apply {
        displayName = name
    }.build()
    user?.updateProfile(profileUpdates)?.addOnCompleteListener { task ->
        if (task.isSuccessful) {
            Timber.d("User profile updated.")
        }
    }
}
the sign out current user function
private fun signOutCurrentUser() {
    firebaseAuth.currentUser?.let {
        firebaseAuth.signOut()
    }
}
The issue is that user is Added successfully but firebaseAuth.currentUser returns null always.
Things I have tried:
- Adding authStateListener
- Adding onSuccessListener
- Adding onCompleteListener
Please help a brother out
 
    