Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Check for Authentication on evry view-Xamarin Forms lab

$
0
0

I have an application with few views. I want to be able to check if user is logged in when any view appears. I am using Xamarin Forms Labs to implement solution in an Mvvm way. To implement this functionality, I created a baseviewmodel and in its constructor I check for logged in status. If the user is not logged in then I want to pop open the login view. Here is the code I used-

public class AuthenticateBaseViewModel:Xamarin.Forms.Labs.Mvvm.ViewModel,IAuthentication
{
public AuthenticateBaseViewModel ()
{
CheckAuthentication ();
}

    #region IAuthentication implementation
    public void CheckAuthentication ()
    {
        if(!App.IsLoggedIn)
            Navigation.PushModalAsync<LoginViewModel>();
    }
    #endregion


}

However Navigation is null and hence I keep getting null reference exception. Even though the BaseViewModel is inheriting from Labs Mvvm class, why is the Navigation null?

Thanks

Apurva


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>