title: How do I carry out Conditional Navigation with Android Jetpack?
body: <p>I am trying to enable users to get to my homepage once they have logged in, but I am trying to do this using Android Conditional Navigation. The problem is I am using android Firebase to authenticate my users before they proceed to this screen and need to create a viewmodel for it but i do not know how to refactor the online guide to achieve this result can anyone point me to what I need to do?</p>
  
  <p>Thank you</p>
  
  <p>Here is the guide for the ViewModel</p>
  
  <pre><code>public class LoginViewModel extends ViewModel {
  
      public enum AuthenticationState {
          UNAUTHENTICATED,        // Initial state, the user needs to authenticate
          AUTHENTICATED,          // The user has authenticated successfully
          INVALID_AUTHENTICATION  // Authentication failed
      }
  
      final MutableLiveData&lt;AuthenticationState&gt; authenticationState =
              new MutableLiveData&lt;&gt;();
      String username;
  
      public LoginViewModel() {
          // In this example, the user is always unauthenticated when MainActivity is launched
          authenticationState.setValue(AuthenticationState.UNAUTHENTICATED);
          username = "";
      }
  
      public void authenticate(String username, String password) {
          if (passwordIsValidForUsername(username, password)) {
              this.username = username;
              authenticationState.setValue(AuthenticationState.AUTHENTICATED);
          } else {
              authenticationState.setValue(AuthenticationState.INVALID_AUTHENTICATION);
          }
      }
  
      public void refuseAuthentication() {
         authenticationState.setValue(AuthenticationState.UNAUTHENTICATED);
      }
  
      private boolean passwordIsValidForUsername(String username, String password) {
          ...
      }
  }
  </code></pre>
  
  <p>Topic reference can be found at : <a href="https://developer.android.com/guide/navigation/navigation-conditional" rel="nofollow noreferrer">https://developer.android.com/guide/navigation/navigation-conditional</a></p>