In my login page when I click on login button with valid email and password, then it goes into homepage. and then when i logged out from there and redirect to login page . then i face is when i clicks on login then it first enter into homepage [even I input any credential or not]. i wants that whenever login button clicks it checks one time. i think its observing previous data.
in login fragment when i click login button i called this method:
   private fun loginCheck(email: String, pass: String) {
   val loginViewModel = ViewModelProvider(this)[LoginViewModel::class.java]
    loginViewModel.loginResponse(requireContext(), email, pass, object : ProgressCallback {
        val opusLoader = OpusProgressLoader(requireContext())
        override fun onStart() {
            opusLoader.customDialogFunctionality(isCancelable = true)
        }
        override fun onFinish() {
            opusLoader.customDialogFunctionality(isCancelable = false)
        }
    })
        .observe(viewLifecycleOwner, Observer { loginPojo ->
            val accessToken = loginPojo.access_token
            if (accessToken.isNotEmpty()) {
                 Navigation.findNavController(requireView()).navigate(R.id.homepage)
                 requireActivity().finish()
            } else Toast.makeText(requireContext(), "Failed", Toast.LENGTH_SHORT).show()
        })
}
my Viewmodel for this :
    class LoginViewModel(application: Application) : AndroidViewModel(application) {
private val loginRepo = AuthRepoImpl.getInstance()
    fun loginResponse(
        context: Context,
        username: String,
        password: String,
        progressCallback: ProgressCallback
    ): LiveData<LoginPojo> {
        return  loginRepo.cLoginResponse(context, username, password,progressCallback)
    }
}
and repository method:
    override fun cLoginResponse(
    context: Context,
    username: String,
    password: String,
    progressCallback: ProgressCallback
): MutableLiveData<LoginPojo> {
    progressCallback.onStart()
    val apiServices = rInstance.getRetrofitInstance()?.create(ApiServices::class.java)
    val requestBody = LoginBody(username, password)
    val call = apiServices?.getUser( requestBody)
    try {
        call?.enqueue(object : Callback<LoginPojo> {
            override fun onResponse(
                call: Call<LoginPojo>,
                response: Response<LoginPojo>
            ) {
                
                progressCallback.onFinish()
                mLivedata.postValue(loginResponse!!)
            }
            override fun onFailure(call: Call<LoginPojo>, t: Throwable) {
                progressCallback.onFinish()
                Toast.makeText(context, "Login Failed", Toast.LENGTH_SHORT).show()
            }
        })
    } catch (e: Exception) {
        e.printStackTrace()
        progressCallback.onFinish()
        Toast.makeText(context, "Login Failed", Toast.LENGTH_SHORT).show()
    }
    return mLivedata
}
 
                        
Clear your live data on your logout Action.