how to skip login page if user is already logged.please help me anyone.
That’s not NEARLY enough information.
if(loggedIn){
rootPage = 'home'
}else {
rootPage = 'login'
}
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();
});
})
}
Does native storage persist data even when the app is relaunched?
Not when you uninstalled app and reinstalled it.
It persist until you uninstall the app.
1 Like