Login/logout issue


#1

Hi,

Im facing an issue regarding with the ionic login/lout development.
After login button click ,setting the userdetails in localstorage (localstorage.setItem()) and route to dashboard.
In dashboard im checking if data present in the localstorage or not, then display the login/logout button

But this isnt working properly, data set in the localstorage is fine.
but when i reach dashboard its still ‘login’ button
When i refresh the dashboard page this will change to ‘logout’ button

Same happening for logout (localstorage.clear()) function too

i am beginner can anyone help me out with this issue

Thanks


#2

First i suggest to get the localstorage value to an variable in the dashboard. then stringfy the value and check your conditions.


#3

It seems to be a component scope problem, where is this button? Inside your dashboard page?


#4

yes, inside the dashboard


#5

hard to track, can you post your code?


#6

How are you checking? Is it in your template? in ionViewWillEnter?


#7

Use ngZone to run your method

import { NgZone } from '@angular/core';
...
constructor (private ngZone: NgZone) {
}

changeButton () {
     if (logged) {
        this.ngZone.run(() => {
            this.showLogoutButton = true;
            this.showLoginButton = false;
        });
     } else {
            this.showLogoutButton = false;
            this.showLoginButton = true;
     }
}