My goal is to display a logout button when the user is logged in and a login button if they are not. I am using JSON tokens to determine if a user is logged in or not, by checking if the token is null. However, this approach does not seem to be working. Can anyone provide assistance?
home.page.ts
admin = false;
constructor(private userService: UserService, private storage: Storage, private router: Router) {}
ngOnInit() {
this.router.navigateByUrl('home');
if (this.storage.get('token') != null) {
this.admin = true;
}
}
home.page.html
<ion-button *ngIf="admin==true">Logout</ion-button>
<ion-button *ngIf="admin==false">Login</ion-button>