Hi,
I am building an ionic 2 app but it happens frequently when I logout and click log in button the app freezes. I am unable to figure out the cause as its not giving any error in console. Even its not showing any error in bugsnag. 6 out 10 times my app freezes when I click log in button. Below is the code snippet of my login page(login.ts) :
import { Component, ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController,MenuController } from 'ionic-angular';
import { HomePage } from '../home/home';
import { Events } from 'ionic-angular';
import { ArtistProfilePage } from '../artist-profile/artist-profile';
import { FanTabs } from '../fan-tabs/fan-tabs';
import {ConfirmUser} from "../confirm-user/confirm-user";
import {ArtistTabs} from "../artist-tabs/artist-tabs";
@Component({
selector: 'login-page',
templateUrl: 'login.html'
})
export class LoginPage {
loginCredentials = { email: '', password: '' };
notConfirmed = true;
fullHeight = '50%';
public latitude: number;
public longitude: number;
menu;
confirmToken;
confirmed;
constructor(menu: MenuController, public navCtrl: NavController, public navParams: NavParams, public events: Events, public alertCtrl: AlertController) {
this.confirmToken = this.navParams.get('confirmToken');
this.menu = menu
this.confirmToken = this.navParams.get('confirmToken');
this.notConfirmed = JSON.parse(localStorage.getItem('register_user'));
this.confirmed = JSON.parse(localStorage.getItem('confirmationMsg'));
if(this.notConfirmed){
this.fullHeight = '25%';
} else if (this.confirmed) {
this.fullHeight = '28%';
}
}
ionViewWillEnter(){
this.menu.enable(false);
if (this.confirmToken != undefined){
var confirmData = {
"action": "confirm-my-account",
"email": this.confirmToken
};
this.events.publish('setData', confirmData);
}
}
ionViewWillLeave(){
this.menu.enable(true);
}
ionViewDidLoad() {
var data = {
'action': 'dummy.request',
}
this.events.publish('setData', data);
localStorage.clear();
this.ngOnInit();
}
public register() {
this.navCtrl.push(ConfirmUser, {});
}
public logIn() {
if(this.loginCredentials.password == ""){
let alert = this.alertCtrl.create({
subTitle: 'Password can not be blank.',
buttons: ['OK']
});
alert.present();
}
else if(this.loginCredentials.email == ""){
let alert = this.alertCtrl.create({
subTitle: 'Email can not be blank.',
buttons: ['OK']
});
alert.present();
}
else{
var data = {
'action': 'users.login',
email: this.loginCredentials.email,
password: this.loginCredentials.password
}
this.events.publish('setData', data);
}
}
}
This is my logout code snippet :
if(page == 'LogOut'){
let alert = this.alertCtrl.create({
message: 'Are you sure, you want to logout?',
buttons: [
{
text: 'No',
role: 'cancel',
handler: () => {
}
},
{
text: 'Yes',
handler: () => {
localStorage.clear();
this.menu.close();
this.nav.setRoot(LoginPage);
this.ws.close();
}
}
]
});
alert.present();
Thanx in advance if any one could help me out.Preformatted text