Problems with NavController. It stops working correctly when I logout


#1

Hello, I have an ionic app with login/registration + validation and a home with a couple of views.
The structure can be something like this:

steps

I don’t have any problem moving through the app, until I use the logout. When that happens when I register, I get to the validation page and when I get the response with the OK from the server I don’t get redirected to the home page. I also get adouble back button in my stacked views.

Maybe I am not cleaning something the right way. I don’t get any error, just everything stops working the right way. Can anybody help me with this problem?

Right now I am using Ionic 3.19.1. Just ask away if you need some more information.

This is my logout:

logout() {
        localStorage.clear();
        this.websocketService.close();
        this.close();
        this.navCtrl.setRoot('LoginPage');
        /* Testing porpose
        this.navCtrl.setRoot('LoginPage').then(() => {
            this.navCtrl.popToRoot();
        });
        */
    }

sms-validation.ts

import { Component } from '@angular/core';
import { IonicPage, NavController, AlertController, App } from 'ionic-angular';
import { AuthServiceProvider } from '../../providers/auth-service/auth-service';
import { NavParams } from 'ionic-angular/navigation/nav-params';

/**
 *
 * Validates the user with a sms code (To be implemented)
 */
@IonicPage()
@Component({
  selector: 'page-sms-validation',
  templateUrl: 'sms-validation.html',
})
export class SmsValidationPage {

  validated = false;
  validationCode: '';
  nickname: '';
 
  constructor(private navCtrl: NavController, private auth: AuthServiceProvider, public alertCtrl: AlertController, public navParams: NavParams, public app: App) {
     
     }
 
  public smsValidation() {
    this.auth.validateCode(this.nickname, this.validationCode).subscribe(response => {
      if (response.status) {
        this.validated = true;
        this.navCtrl.setRoot('HomePage');
        this.showPopup("Success", "Account validated.");
      } else {
        this.showPopup("Error", "Problem validating account. " + response.message);
      }
    },
      error => {
        this.showPopup("Error", error.message);
      });
  }
  
  showPopup(title, text) {
    let alert = this.alertCtrl.create({
      title: title,
      subTitle: text,
      buttons: [
        {
          text: 'OK',
          handler: data => {
            if (this.validated) {
              this.navCtrl.setRoot('HomePage');
            }
          }
        }
      ]
    });
    alert.present();
  }
  
  ionViewDidLoad() {}

}

app.html

<ion-nav [root]="rootPage"></ion-nav>