$urlRouterProvider depending upon user login status


#1

Hello, all of you
In My app there is single time user login, this means that When user install my app there is login view for login, at this stage i am storing his status in sqlite database. After successfully login it will navigate to main dashboard screen. Then after reopen my app after closing it he will navigate to main dashboard depending upon login status which is get from sqlite database.

I am tried it with blank controller, Here i will check the status value fetching from sqlite database in blank controller if i get status true then it will navigate to main page, if not then login view.

But there is one problem after starting of app after closing or new opening the blank controller is load and it will take some time to navigate either login or main dashboard screen.

I want to do this operation on splash screen loading, In Android such operations happened on splash screen. So my question is How it will do in ionic same like android and ios splash screen for user login status check?

please help me if you have any example or good tutorial for it.

Thanks you in advance


#2

hi,
try to do this with
resolve before the view is rendered


#3

@ItamarCohen
Can you elaborate with example…Please


#4

hi,

.service('authCheckService', ['$http', '$q', 'localStorageService', function ($http, $q, localStorageService) {
var self = {
    'onlyLoggedIn': function ($state, $q) {
        var deferred = $q.defer();
        var authData = localStorageService.get('authorizationData');
        console.log(authData);
        if (authData) {
            deferred.resolve();
        } else {
            deferred.reject();
            $state.go('login');
        }
        return deferred.promise;
    }
}

  return self;
}]);

.state('smo-dashboard', {
    url: '/dashboard',
    templateUrl: 'dashboard.html',
    resolve: authCheckServiceProvider.onlyLoggedIn
})

#5

Thanks for your replay, But i want to fetch sqlite data means login status form database, How it will implement in service…?


#6

inject the plugin to the service and retrieve the data and set var authData


#7

After trying your solution i will put all code inside my app.
When i run it on browser the resolve: authCheckServiceProvider.onlyLoggedIn this line give me undefined i think onlyLoggedIn is not defined or not set value any where in my app.

How to resolve this issue
Please help me…
Thank you !!