Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

App login flow

plettbplettb Member

I'm quite new to Xamarin development and have what is likely a very simple problem. I'd like the first thing to happen in my app to be a login. The login is pretty much exactly the same as the "Web Authenticator" sample in the Xamarin Essentials samples. However, it's the flow that I'm struggling to figure out. I'd like that to be the entry point of my app. Upon successful login, the rest of the app becomes usable. However, if login fails, I'd like to display a "retry or exit". In other words, I'd display the login page first, and only display the main page upon successful login, and exiting the app without it.

Whereas it embarrasses me to ask such a trivial question, doing so might save me a lot of time and end up with a better solution than if I just grind my way through it. So, good instructions or a code example would be much appreciated.

Note that initially this is just for Android, but I'd like to do the same with the iOS and UWP versions eventually.

Thanks!
Brad.

Posts

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Very basic skeleton, just get a reference to App with (App)Application.Current and call these methods to swap out the main page of your app. There is also an Application.Quit() method but it's not really recommended to use.

    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
            ShowLogin();
        }
    
        public void ShowLogin()
        {
            MainPage = new NavigationPage(new LoginPage());
        }
    
        public void ShowMainPage()
        {
            MainPage = new NavigationPage(new MainPage());
        }
    }
    
  • plettbplettb Member

    Thanks! That was enough to point me in the right direction.

Sign In or Register to comment.