How to make login better

This is my current Login. I have to check if the user type is User or Restaurant. Its kind of slow because of “observeAsState”. Could someone show me a better and efficient solution please?

loginViewModel.loginStatus.observeAsState(loginViewModel.loginStatus).apply {
                if (this.value == true) {
                    loginViewModel.userInfo.observeAsState(null).apply {
                        if (this.value!=null) {
                            val isUser = loginViewModel.userInfo.value?.isUser
                            showProgress = false
                            if (isUser == true) {
                                println("USERRRRR")
                                NavigateToUsers()
                            } else {
                                println("RESTAURAMT")
                                NavigateToRestaurants()
                            }
                        }
                    }

                }
                if(this.value == false)
                {
                    Toast.makeText(context, "Can't join. Wrong password!", Toast.LENGTH_LONG).show()
                }
            }

Hello @Ciprian_Gabor :wave:,

Welcome to MongoDB Community :star_struck:

From your description, it appears you are designing an app related to food. I would recommend looking at some of the MongoDB Mobile Documentation. Some resources are linked here below:

  1. MongoDB Developer Center
  2. Mobile Tutorials (To-do App) in all SDKs
  3. Realm Bytes on getting started

Could you briefly explain the use case or the workflow of your application, to give you the help and support you need for implementing the feature?

I hope the provided information is helpful.

Cheers, :performing_arts:
Henna

My app has 2 user types: User and Restaurant. The User collection has a field called: “isUser: Boolean” which determines if its user or restaurant.
The login function should check if its user or restaurant. Currently this is my login, but its kinda slow:

            loginViewModel.loginStatus.observeAsState(loginViewModel.loginStatus).apply {
                if (this.value == true) {
                    loginViewModel.userInfo.observeAsState(null).apply {
                        if (this.value!=null) {
                            val isUser = loginViewModel.userInfo.value?.isUser
                            showProgress = false
                            if (isUser == true) {
                                println("USERRRRR")
                                NavigateToUsers()
                            } else {
                                println("RESTAURAMT")
                                NavigateToRestaurants()
                            }
                        }
                    }

                }
                if(this.value == false)
                {
                    Toast.makeText(context, "Can't join. Wrong password!", Toast.LENGTH_LONG).show()
                }
            }