Hi, I´m developing an Ionic / Angular APP and for save and get token´s user I’m using storage The problem is that I am facing problem when trying to get the token, In fact I have to try two or more times to finally receive the token.
On the home screen I simulate a login with the data I need:
import { Storage } from '@ionic/storage';
private _Storage: Storage
this._Storage.set('X-Access-Token', 'f27bf5399b81c701bd9d6158ca67bb58');
this._Storage.set('isLogged', 'true');
this._Router.navigate(['/dashboard']);
To be able to retrieve the X-Access-Token in the compoment dashboard (and all other components) I have to call the GetAccessToken function with ngOnInit, and then inside the main function of each component.
XAccessToken: any;
ngOnInit() {
this.GetXAccessToken();
}
GetXAccessToken() {
this._Storage.get('X-Access-Token').then((token) => {
this.XAccessToken = token;
});
}
ionViewDidEnter() {
this.GetChannelsFollowed();
}
async GetChannelsFollowed() {
this.GetXAccessToken();
....
}
2 posts - 2 participants