Ionic start page depending on a condition


#1

Hi, I am relatively new to ionic and building an app where I want to route the user to a input screen when he logs in for the first time and then to the standard login screen when he launches the app for the second time.
Links / Ideas anyone?
Thanks, EL


#2

You would start with something like this

And then set up a login service like this


#3

Thanks! I’ll have a look into that! :smile:


#4

I’m interest in this functionnality.
i post principally for follow the post and have an update if the functionnaly sort :wink:

@elduderino15 : do you think is possible to have an easy facebook connect for ionic ?
(in my last test, phonegap plugin is not functionnaly and angular fb is not also… i don’t search so much…)
thank…


#5

mhartington, I simply didnt undertand how that helps=\

I just want to understand how you define the ion-nav-view what state to load first.
I want it to check if the user have a auth token saved locally and based on that choose to load the “welcome” page or the “profile” page.

the closest i got was working with events. it worked but im still see a glimps of my welcome page before routing to the profile page.

Isnt there a simple way to tell the router what state to inject the ion-nav-view?
im stuck on that for hours and its shuold be the most simple thing.


#6

So you need to break it down which is what the login page does. You could if you wanted to make it difficult and do it in the angular run function or tie a bunch of events together. But the best way is to have a type of landing controller. So you’d first navigate to like a /landing state that you make, and that controller will run the logic of testing the authentication and then depending on how that goes you just direct them to the next states whether it’s login or home.

In my app, I actually have my login page as my landing page, and it checks the authentication there and if it passes, it automatically logs them in and moves them along with $state.go(‘home’);

Also to make it cleaner for the user I programmatically hide the splash screen after I check the auth that way it doesn’t show the app moving between states.


#7

I dont know if it is a beautiful solution, but just works for me. I store auth info in local storage, so in my app.config I put a condition like this:

if(window.localStorage[‘authStuff’]){
$urlRouterProvider.otherwise(’/home’);
}else{
$urlRouterProvider.otherwise(’/login’);
}

If anyone have questions about my code, please let me know.


#8

if(window.localStorage[‘authStuff’]){
$urlRouterProvider.otherwise(’/home’);
}else{
$urlRouterProvider.otherwise(’/login’);
}

This solutions works on android but not iphone…any clue why?

Thanks


#9

in which function did u include like this?


#10

if you are using $stateProvider, you have something like this

app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider .state(’’, {…
…});

// authStuff code here
});