Problem with use storage

hi
i make login form
after succesfull login i save userID with storage like this

this.storage.set('Is_logged', "true");

and i want when the page load first check if Is_logged == true alert me
this is my code

this.storage.get('Is_logged').then((Is_logged) => {
this.Is_logged = JSON.parse(Is_logged);
console.log(this.Is_logged);
})

if (this.Is_logged === 'true') {

  alert("true!!!");

}

else {

  alert("false");
}

but it always alert false
where is problem ?
any idea ?

Basic async coding, you alert before you get the value from storage. However you do log after you get it, so I’d imagine it shows up properly in the console right? You should read about async coding and promises, it’s not really an Ionic thing, just a basic javascript thing.

1 Like