Registration in ionic


#1

Hi,

I’m trying to build a registration views, but my problem is that the check if the user is already register in the $ionicPlatform.ready, there I do the following:

    $ionicPlatform.ready(function() {

        db = $cordovaSQLite.openDB({ name: "my.db" });
        $cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS groups (id integer primary key, title text)");

        if (typeof(Storage) != "undefined") {
            // Store
            var registered = localStorage["isRegistered"];
            if(registered == undefined || !registered){
                $location.path('/register');
            }else{
                $location.path('/tab/groups');
            }
        }
    });

But my problem that the mechanism of the angular, firstly going to the $urlRouterProvider.otherwise('/tab/groups') and then the going to the ready of Ionic, it means that in the first opening of the application, it appear the groups tab then going to the registration view.
I tried to put the check if the user is already registered in the otherwise like the following:

$urlRouterProvider.otherwise(function($injector, $location){
    if (typeof(Storage) != "undefined") {
        // Store
        var registered = localStorage["isRegistered"];
        if(registered == undefined || !registered){
            $location.path('/register');
        }else{
            $location.path('/tab/groups');
        }
    }
});

But the problem that we arrive to the groups tab before we open that database, in the groups controller we got the groups from the database!
Is there any solution to do the registration?