Forum Xamarin.Forms

Xamarin Forms 4.0 Shell Navigation - Login Page

I am trying to implement a simple login page in my app using shell. I check some posts but none of them could fix my problem.

In my app.xaml.cs I have two options: if user was logged => MainPage = new AppShell(); otherwise MainPage = new Login(); That approach appears to work fine, and I can see the right page after successfull logon.

The shell navigation page have a tab with a logout page, and here is my problem. If I use App.Current.MainPage = new Login(); the page overlap the content of my current shell page!

What´s the best approach to implement login page using shell navigation? Anyone know where can I find a sample project?

Any help will be appreciate.

Posts

  • Christopher_MillerChristopher_Miller USUniversity ✭✭

    I'm facing a similar problem. What would be the best practice to invoke a login page when using the Shell?

    When the user starts up the app and their session token is invalid, I want to use Navigation.PushModalAsync() to call the login page. I was using AppShell.OnNavigated(), but it appears to get called twice when the app first starts. Is there a better alternative to using OnNavigated() or should I just add code so that the second call to OnNavigated() is ignored if the the login page is open?

  • PierreSavardPierreSavard CAMember ✭✭

    Same problem here. Do you find a good way to do that?

  • enriqueDenriqueD USMember

    I have the same problem, someone has already found the solution for a login and then load the AppShell

  • DmitriyBardayDmitriyBarday USMember
            public AppShell()
            {
                InitializeComponent();
    
                _settingsService = DependencyService.Resolve<ISettingsService>(DependencyFetchTarget.GlobalInstance);
                if (string.IsNullOrWhiteSpace(_settingsService.AuthToken))
                {
                    this.Navigation.PushModalAsync(new LogonPage());
                }
    
            }
    

    I use this code. You also can look on the implementation of login page here: github com/microsoft/TailwindTraders-Mobile

  • wagenheimerwagenheimer Member ✭✭

    Same problem here! Does anybody have any solution?

  • ThomasEveringhamThomasEveringham USMember ✭✭

    Try setting background colour for your root Layout control, e.g.

    <Grid Margin="0,0,0,0" BackgroundColor="White">

  • ThomasEveringhamThomasEveringham USMember ✭✭

    Additional. Sample application showing use of login page with shell:

    https://github.com/davidortinau/ShellLoginSample/tree/master/ShellLoginSample

    Note: this sample has a menu button and flyout on the login page. You can hide this with:
    ShellInstance.FlyoutBehavior = FlyoutBehavior.Disabled;

  • Bolu.6501Bolu.6501 ZAMember

    Does anyone have a sample app using Facebook and Google as login

  • DamienDoumerDamienDoumer USMember ✭✭

    @Bolu.6501 Here is a sample application having both facebook and google login, and in the article, you can even find an asp.net core back-end to manage user logins with JWT token and all the like... You can find it by following this link: https: //doumer.me/social-auth-with-xamarin-forms-and-asp-net-core-api/

Sign In or Register to comment.