How to skip login page if user is already logged


#1

how to skip login page if user is already logged.please help me anyone.


#2

That’s not NEARLY enough information.

if(loggedIn){
   rootPage = 'home'
}else {
   rootPage = 'login'
}

#3

Maybe this will help you. Use Native Storage plugin :-

constructor(
private navCtrl: NavController,
private http: Http,
private storage: Storage,
public loading: LoadingController,
private alertCtrl: AlertController,
private menu: MenuController
) {
this.checkStorage();
this.menu.swipeEnable(false, ‘menu’);
}

errorAlert() {
    let alert = this.alertCtrl.create({
        title: 'Sorry',
        subTitle: 'No record found',
        buttons: ['Ok']
    });
    alert.present();
}

checkStorage(){
    this.storage.get('userData').then((val) => {
        console.log(val);
        if ( val != null ){
            console.log('Your name is', val.email);
            //this.navCtrl.push(HomePage,{});
            this.navCtrl.setRoot(HomePage);
        }else{
            console.log('No value');
        }
    });

}

login(){
    let loader = this.loading.create({
        content: 'Please Wait...',
    });
    let body = 'username=' + this.users.username + '&password=' + this.users.password;
    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');
    loader.present().then(() => {
        this.http
            .post('http://xyz.com/api/api.php?action=login',
                body, {
                    headers: headers
                })
            .subscribe(res => {
                if(res.json() == null){
                        this.errorAlert();
                        loader.dismiss();
                }  else{
                    this.dataArray = res.json();
                    this.storage.set('userData', this.dataArray);
                    //this.navCtrl.push(HomePage, {});
                    this.navCtrl.setRoot(HomePage);
                    loader.dismiss();
                }
            }, error => {
                console.log(JSON.stringify(error.json()));
                loader.dismiss();
            });
    })
}

#4

#5

Does native storage persist data even when the app is relaunched?


#6

Not when you uninstalled app and reinstalled it.
It persist until you uninstall the app.