I have an app with one activity and about 29 Fragment in the nav_graph, two of these fragments are used for authentication, and I need to share data between these two fragments using a shared view model but not with the other fragments.
So, I created my ViewModel and instantiated it in both fragments using the viewModels() which is a part of fragment-ktx library.
private val viewModel: AuthViewModel by viewModels()
However, once I navigate to the second fragment using the findNavController().navigate() I lose all the data in the AuthViewModel
AuthViewModel.kt
class AuthViewModel @ViewModelInject constructor(
private val authRepository: AuthRepository
) : BaseViewModel()
Is there any additional step I'm missing here?
EDIT
I'm accessing the data from the onViewCreated method