App does not go through login

1

I'm trying to validate login , but it's passing right by and entering home , I do not know what might be happening:

import { Component } from '@angular/core';
import {LoginPage} from '../login/login';
import { NavController } from 'ionic-angular';

@Component({ 
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController) {
      window.localStorage.removeItem('currentuser');
   if(this.isLoggedin()){
       console.log('you are not logged in');
       this.navCtrl.push(LoginPage);
   }
  }
    isLoggedin(){
        if(window.localStorage.getItem('currentuser')){
            return true;
        }
    }
}
    
asked by anonymous 24.03.2017 / 03:47

1 answer

2

The problem lies in your logic. At first you need to check if it is different from "logged in". For example: !this.isLoggedin() . See below:

if(!this.isLoggedin()){
   console.log('you are not logged in');
   this.navCtrl.push(Login);
}

Thus, your isLoggedin() method can be checked whether or not there is an item saved in its localStorege with the corresponding value. If it exists, return true , otherwise return false . See:

isLoggedin(){ 
   return window.localStorage.getItem('currentuser'); 
}
    
24.03.2017 / 04:31