Ionic2 Log in and


#1

Hi,

I am creating an App with Ionic2 and the requirement is -

  • the app when first loaded will show a Log In page and when logged in
  • will have a Side-Menu enabled pages

The starter project shows that the Side Menu as the root of the app and loads first before any other page is open - then it loads the other related pages.

How can I build an app that Loads Log In page first and then set the Side Menu as the main navigation and never shows up the Log In screen??


#2

Hello All,

kind Attn [vahid najafi & Aish123]

I tried something more easy and I found it working.

  • I set the LogIn page as the root when the app first loaded - and I removed ‘menuToggle’ button from this template.

  • Then I imported the Component I want to redirect to after successful Log in

  • I created a singIn function in LogInPage class as follows:

      signIn (){    
          let navRef = this.app.getComponent('nav');    
          navRef.setRoot(HelloIonicPage);
      }
    

and it worked like a charm


#4

I did tabs… how do I logout then??? I tried it but the tabs still remain…


#5

I have the same sort of app flow with the login and side menu. I also use tabs too. I used the setPages method in login function.

nav.setPages([{page: SideMenu}], {animate: true});

And for logout this for the logout fiction.

this.nav.rootNav.setRoot(LoginPage);


#6

Have you tried to create a separate Component for log In ?

Or you can use a Modal for logging in … when users open the app - the code will check if the user is already logged in or not. Depending on the response - users can be directed to navigate inside the app.