app.component.ts

import { Component, ViewChild } from '@angular/core';
import { BackandService } from '@backand/angular2-sdk'
import { NavController, Platform } from 'ionic-angular';
import { NativeStorage, StatusBar, Splashscreen } from 'ionic-native';

import { HomeComponent } from './components/home/home.component';
import { SlidesComponent } from './components/slides/slides.component';

@Component({
    template: '<ion-nav #appNav [root]="rootPage"></ion-nav>'
})
export class AppComponent {
    @ViewChild('appNav') navCtrl: NavController

    constructor(platform: Platform, private backand:BackandService) {
        platform.ready().then(() => {
            // Set backand service params
            backand.init({
                appName: 'Creepy Chat',
                signUpToken: 'a91fd98e-48c9-4889-b66c-c2e4e9908038',
                anonymousToken: '86db325b-2218-415d-b96b-f27967e77ff2',
                isMobile: platform.is('mobile')
            });

            // Here we will check if the user is already logged in
            // because we don't want to ask users to log in each time they open the app
            var nav = this.navCtrl;
            NativeStorage.getItem('user')
            .then( function (data) {
                // user is previously logged and we have his data
                // we will let him access the app
                nav.push(HomeComponent);
                Splashscreen.hide();
            }, function (error) {
                //we don't have the user data so we will ask him to log in
                nav.push(SlidesComponent);
                Splashscreen.hide();
            });

            StatusBar.styleDefault();
        });
    }
}